2 Implementation for EFI_HII_STRING_PROTOCOL.
5 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
19 CHAR16 mLanguageWindow
[16] = {
20 0x0000, 0x0080, 0x0100, 0x0300,
21 0x2000, 0x2080, 0x2100, 0x3000,
22 0x0080, 0x00C0, 0x0400, 0x0600,
23 0x0900, 0x3040, 0x30A0, 0xFF00
28 This function checks whether a global font info is referred by local
29 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
30 a HII_FONT_INFO to refer it locally.
32 This is a internal function.
35 @param Private Hii database private structure.
36 @param StringPackage HII string package instance.
37 @param FontId Font identifer, which must be unique within the string package.
38 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
39 the same EFI_FONT_INFO is permitted. Otherwise it
41 @param GlobalFontInfo Input a global font info which specify a
43 @param LocalFontInfo Output a local font info which refers to a
46 @retval TRUE Already referred before calling this function.
47 @retval FALSE Not referred before calling this function.
51 ReferFontInfoLocally (
52 IN HII_DATABASE_PRIVATE_DATA
*Private
,
53 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
55 IN BOOLEAN DuplicateEnable
,
56 IN HII_GLOBAL_FONT_INFO
*GlobalFontInfo
,
57 OUT HII_FONT_INFO
**LocalFontInfo
60 HII_FONT_INFO
*LocalFont
;
63 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& GlobalFontInfo
!= NULL
&& LocalFontInfo
!= NULL
);
65 if (!DuplicateEnable
) {
66 for (Link
= StringPackage
->FontInfoList
.ForwardLink
;
67 Link
!= &StringPackage
->FontInfoList
;
68 Link
= Link
->ForwardLink
70 LocalFont
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
71 if (LocalFont
->GlobalEntry
== &GlobalFontInfo
->Entry
) {
73 // Already referred by local font info list, return directly.
75 *LocalFontInfo
= LocalFont
;
80 // FontId identifies EFI_FONT_INFO in local string package uniquely.
81 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
82 // EFI_FONT_INFO uniquely in whole hii database.
84 LocalFont
= (HII_FONT_INFO
*) AllocateZeroPool (sizeof (HII_FONT_INFO
));
85 ASSERT (LocalFont
!= NULL
);
87 LocalFont
->Signature
= HII_FONT_INFO_SIGNATURE
;
88 LocalFont
->FontId
= FontId
;
89 LocalFont
->GlobalEntry
= &GlobalFontInfo
->Entry
;
90 InsertTailList (&StringPackage
->FontInfoList
, &LocalFont
->Entry
);
92 *LocalFontInfo
= LocalFont
;
98 Convert Ascii string text to unicode string test.
100 This is a internal function.
103 @param StringDest Buffer to store the string text. If it is NULL,
104 only the size will be returned.
105 @param StringSrc Points to current null-terminated string.
106 @param BufferSize Length of the buffer.
108 @retval EFI_SUCCESS The string text was outputed successfully.
109 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
110 text. BufferSize is updated to the required buffer
115 ConvertToUnicodeText (
116 OUT EFI_STRING StringDest
,
118 IN OUT UINTN
*BufferSize
124 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
126 StringSize
= AsciiStrSize (StringSrc
) * 2;
127 if (*BufferSize
< StringSize
|| StringDest
== NULL
) {
128 *BufferSize
= StringSize
;
129 return EFI_BUFFER_TOO_SMALL
;
132 for (Index
= 0; Index
< AsciiStrLen (StringSrc
); Index
++) {
133 StringDest
[Index
] = (CHAR16
) StringSrc
[Index
];
136 StringDest
[Index
] = 0;
142 Calculate the size of StringSrc and output it. If StringDest is not NULL,
143 copy string text from src to dest.
145 This is a internal function.
147 @param StringDest Buffer to store the string text. If it is NULL,
148 only the size will be returned.
149 @param StringSrc Points to current null-terminated string.
150 @param BufferSize Length of the buffer.
152 @retval EFI_SUCCESS The string text was outputed successfully.
153 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
154 text. BufferSize is updated to the required buffer
159 GetUnicodeStringTextOrSize (
160 OUT EFI_STRING StringDest
, OPTIONAL
162 IN OUT UINTN
*BufferSize
168 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
170 StringSize
= sizeof (CHAR16
);
171 StringPtr
= StringSrc
;
172 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
173 StringSize
+= sizeof (CHAR16
);
174 StringPtr
+= sizeof (CHAR16
);
177 if (*BufferSize
< StringSize
) {
178 *BufferSize
= StringSize
;
179 return EFI_BUFFER_TOO_SMALL
;
181 if (StringDest
!= NULL
) {
182 CopyMem (StringDest
, StringSrc
, StringSize
);
185 *BufferSize
= StringSize
;
191 Copy string font info to a buffer.
193 This is a internal function.
195 @param StringPackage Hii string package instance.
196 @param FontId Font identifier which is unique in a string
198 @param StringFontInfo Buffer to record the output font info. It's
199 caller's responsibility to free this buffer.
201 @retval EFI_SUCCESS The string font is outputed successfully.
202 @retval EFI_NOT_FOUND The specified font id does not exist.
207 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
209 OUT EFI_FONT_INFO
**StringFontInfo
213 HII_FONT_INFO
*FontInfo
;
214 HII_GLOBAL_FONT_INFO
*GlobalFont
;
216 ASSERT (StringFontInfo
!= NULL
&& StringPackage
!= NULL
);
218 for (Link
= StringPackage
->FontInfoList
.ForwardLink
; Link
!= &StringPackage
->FontInfoList
; Link
= Link
->ForwardLink
) {
219 FontInfo
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
220 if (FontInfo
->FontId
== FontId
) {
221 GlobalFont
= CR (FontInfo
->GlobalEntry
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
222 *StringFontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (GlobalFont
->FontInfoSize
);
223 if (*StringFontInfo
== NULL
) {
224 return EFI_OUT_OF_RESOURCES
;
226 CopyMem (*StringFontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
231 return EFI_NOT_FOUND
;
236 Parse all string blocks to find a String block specified by StringId.
237 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
238 within this string package and backup its information. If LastStringId is
239 specified, the string id of last string block will also be output.
240 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_STRING).
242 @param Private Hii database private structure.
243 @param StringPackage Hii string package instance.
244 @param StringId The string's id, which is unique within
246 @param BlockType Output the block type of found string block.
247 @param StringBlockAddr Output the block address of found string block.
248 @param StringTextOffset Offset, relative to the found block address, of
249 the string text information.
250 @param LastStringId Output the last string id when StringId = 0 or StringId = -1.
251 @param StartStringId The first id in the skip block which StringId in the block.
253 @retval EFI_SUCCESS The string text and font is retrieved
255 @retval EFI_NOT_FOUND The specified text or font info can not be found
257 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
263 IN HII_DATABASE_PRIVATE_DATA
*Private
,
264 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
265 IN EFI_STRING_ID StringId
,
266 OUT UINT8
*BlockType
, OPTIONAL
267 OUT UINT8
**StringBlockAddr
, OPTIONAL
268 OUT UINTN
*StringTextOffset
, OPTIONAL
269 OUT EFI_STRING_ID
*LastStringId
, OPTIONAL
270 OUT EFI_STRING_ID
*StartStringId OPTIONAL
274 EFI_STRING_ID CurrentStringId
;
277 UINT8
*StringTextPtr
;
279 HII_FONT_INFO
*LocalFont
;
280 EFI_FONT_INFO
*FontInfo
;
281 HII_GLOBAL_FONT_INFO
*GlobalFont
;
285 EFI_HII_FONT_STYLE FontStyle
;
288 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
294 ASSERT (StringPackage
!= NULL
);
295 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
299 if (StringId
!= (EFI_STRING_ID
) (-1) && StringId
!= 0) {
300 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
301 if (StringId
> StringPackage
->MaxStringId
) {
302 return EFI_NOT_FOUND
;
305 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
306 if (StringId
== 0 && LastStringId
!= NULL
) {
307 *LastStringId
= StringPackage
->MaxStringId
;
312 ZeroMem (&Zero
, sizeof (CHAR16
));
315 // Parse the string blocks to get the string text and font.
317 BlockHdr
= StringPackage
->StringBlock
;
320 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
322 case EFI_HII_SIBT_STRING_SCSU
:
323 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
324 StringTextPtr
= BlockHdr
+ Offset
;
325 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
329 case EFI_HII_SIBT_STRING_SCSU_FONT
:
330 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
331 StringTextPtr
= BlockHdr
+ Offset
;
332 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
336 case EFI_HII_SIBT_STRINGS_SCSU
:
337 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
338 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
);
339 BlockSize
+= StringTextPtr
- BlockHdr
;
341 for (Index
= 0; Index
< StringCount
; Index
++) {
342 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
343 if (CurrentStringId
== StringId
) {
344 *BlockType
= *BlockHdr
;
345 *StringBlockAddr
= BlockHdr
;
346 *StringTextOffset
= StringTextPtr
- BlockHdr
;
349 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
354 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
357 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
360 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
361 BlockSize
+= StringTextPtr
- BlockHdr
;
363 for (Index
= 0; Index
< StringCount
; Index
++) {
364 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
365 if (CurrentStringId
== StringId
) {
366 *BlockType
= *BlockHdr
;
367 *StringBlockAddr
= BlockHdr
;
368 *StringTextOffset
= StringTextPtr
- BlockHdr
;
371 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
376 case EFI_HII_SIBT_STRING_UCS2
:
377 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
378 StringTextPtr
= BlockHdr
+ Offset
;
380 // Use StringSize to store the size of the specified string, including the NULL
383 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
384 BlockSize
+= Offset
+ StringSize
;
388 case EFI_HII_SIBT_STRING_UCS2_FONT
:
389 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
390 StringTextPtr
= BlockHdr
+ Offset
;
392 // Use StrSize to store the size of the specified string, including the NULL
395 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
396 BlockSize
+= Offset
+ StringSize
;
400 case EFI_HII_SIBT_STRINGS_UCS2
:
401 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
402 StringTextPtr
= BlockHdr
+ Offset
;
404 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
405 for (Index
= 0; Index
< StringCount
; Index
++) {
406 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
407 BlockSize
+= StringSize
;
408 if (CurrentStringId
== StringId
) {
409 *BlockType
= *BlockHdr
;
410 *StringBlockAddr
= BlockHdr
;
411 *StringTextOffset
= StringTextPtr
- BlockHdr
;
414 StringTextPtr
= StringTextPtr
+ StringSize
;
419 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
420 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
421 StringTextPtr
= BlockHdr
+ Offset
;
425 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
428 for (Index
= 0; Index
< StringCount
; Index
++) {
429 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
430 BlockSize
+= StringSize
;
431 if (CurrentStringId
== StringId
) {
432 *BlockType
= *BlockHdr
;
433 *StringBlockAddr
= BlockHdr
;
434 *StringTextOffset
= StringTextPtr
- BlockHdr
;
437 StringTextPtr
= StringTextPtr
+ StringSize
;
442 case EFI_HII_SIBT_DUPLICATE
:
443 if (CurrentStringId
== StringId
) {
445 // Incoming StringId is an id of a duplicate string block.
446 // Update the StringId to be the previous string block.
447 // Go back to the header of string block to search.
451 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
),
452 sizeof (EFI_STRING_ID
)
454 ASSERT (StringId
!= CurrentStringId
);
458 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
463 case EFI_HII_SIBT_SKIP1
:
464 SkipCount
= (UINT16
) (*(BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
465 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
466 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
469 case EFI_HII_SIBT_SKIP2
:
470 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
471 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
472 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
475 case EFI_HII_SIBT_EXT1
:
478 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
481 BlockSize
+= Length8
;
484 case EFI_HII_SIBT_EXT2
:
485 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
486 if (Ext2
.BlockType2
== EFI_HII_SIBT_FONT
&& StringId
== (EFI_STRING_ID
) (-1)) {
488 // Find the relationship between global font info and the font info of
489 // this EFI_HII_SIBT_FONT block then backup its information in local package.
491 BlockHdr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
492 CopyMem (&FontId
, BlockHdr
, sizeof (UINT8
));
493 BlockHdr
+= sizeof (UINT8
);
494 CopyMem (&FontSize
, BlockHdr
, sizeof (UINT16
));
495 BlockHdr
+= sizeof (UINT16
);
496 CopyMem (&FontStyle
, BlockHdr
, sizeof (EFI_HII_FONT_STYLE
));
497 BlockHdr
+= sizeof (EFI_HII_FONT_STYLE
);
498 GetUnicodeStringTextOrSize (NULL
, BlockHdr
, &StringSize
);
500 FontInfoSize
= sizeof (EFI_FONT_INFO
) - sizeof (CHAR16
) + StringSize
;
501 FontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (FontInfoSize
);
502 if (FontInfo
== NULL
) {
503 return EFI_OUT_OF_RESOURCES
;
505 FontInfo
->FontStyle
= FontStyle
;
506 FontInfo
->FontSize
= FontSize
;
507 CopyMem (FontInfo
->FontName
, BlockHdr
, StringSize
);
510 // If find the corresponding global font info, save the relationship.
511 // Otherwise ignore this EFI_HII_SIBT_FONT block.
513 if (IsFontInfoExisted (Private
, FontInfo
, NULL
, NULL
, &GlobalFont
)) {
514 ReferFontInfoLocally (Private
, StringPackage
, FontId
, TRUE
, GlobalFont
, &LocalFont
);
518 // Since string package tool set FontId initially to 0 and increases it
519 // progressively by one, StringPackage->FondId always represents an unique
520 // and available FontId.
522 StringPackage
->FontId
++;
527 BlockSize
+= Ext2
.Length
;
531 case EFI_HII_SIBT_EXT4
:
534 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
538 BlockSize
+= Length32
;
545 if (StringId
> 0 && StringId
!= (EFI_STRING_ID
)(-1)) {
546 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
547 *BlockType
= *BlockHdr
;
548 *StringBlockAddr
= BlockHdr
;
549 *StringTextOffset
= Offset
;
551 if (StringId
== CurrentStringId
- 1) {
553 // if only one skip item, return EFI_NOT_FOUND.
555 if(*BlockType
== EFI_HII_SIBT_SKIP2
|| *BlockType
== EFI_HII_SIBT_SKIP1
) {
556 return EFI_NOT_FOUND
;
562 if (StringId
< CurrentStringId
- 1) {
563 return EFI_NOT_FOUND
;
566 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
567 if (StartStringId
!= NULL
) {
568 *StartStringId
= CurrentStringId
;
573 // Get last string ID
575 if (StringId
== (EFI_STRING_ID
) (-1)) {
576 *LastStringId
= (EFI_STRING_ID
) (CurrentStringId
- 1);
580 return EFI_NOT_FOUND
;
585 Parse all string blocks to get a string specified by StringId.
587 This is a internal function.
589 @param Private Hii database private structure.
590 @param StringPackage Hii string package instance.
591 @param StringId The string's id, which is unique within
593 @param String Points to retrieved null-terminated string.
594 @param StringSize On entry, points to the size of the buffer pointed
595 to by String, in bytes. On return, points to the
596 length of the string, in bytes.
597 @param StringFontInfo If not NULL, allocate a buffer to record the
598 output font info. It's caller's responsibility to
601 @retval EFI_SUCCESS The string text and font is retrieved
603 @retval EFI_NOT_FOUND The specified text or font info can not be found
605 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
611 IN HII_DATABASE_PRIVATE_DATA
*Private
,
612 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
613 IN EFI_STRING_ID StringId
,
614 OUT EFI_STRING String
,
615 IN OUT UINTN
*StringSize
, OPTIONAL
616 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
619 UINT8
*StringTextPtr
;
621 UINT8
*StringBlockAddr
;
622 UINTN StringTextOffset
;
626 ASSERT (StringPackage
!= NULL
);
627 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
630 // Find the specified string block
632 Status
= FindStringBlock (
642 if (EFI_ERROR (Status
)) {
646 if (StringSize
== NULL
) {
648 // String text buffer is not requested
654 // Get the string text.
656 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
658 case EFI_HII_SIBT_STRING_SCSU
:
659 case EFI_HII_SIBT_STRING_SCSU_FONT
:
660 case EFI_HII_SIBT_STRINGS_SCSU
:
661 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
662 Status
= ConvertToUnicodeText (String
, (CHAR8
*) StringTextPtr
, StringSize
);
664 case EFI_HII_SIBT_STRING_UCS2
:
665 case EFI_HII_SIBT_STRING_UCS2_FONT
:
666 case EFI_HII_SIBT_STRINGS_UCS2
:
667 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
668 Status
= GetUnicodeStringTextOrSize (String
, StringTextPtr
, StringSize
);
671 return EFI_NOT_FOUND
;
673 if (EFI_ERROR (Status
)) {
678 // Get the string font. The FontId 0 is the default font for those string blocks which
679 // do not specify a font identifier. If default font is not specified, return NULL.
681 if (StringFontInfo
!= NULL
) {
683 case EFI_HII_SIBT_STRING_SCSU_FONT
:
684 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
685 case EFI_HII_SIBT_STRING_UCS2_FONT
:
686 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
687 FontId
= *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
692 Status
= GetStringFontInfo (StringPackage
, FontId
, StringFontInfo
);
693 if (Status
== EFI_NOT_FOUND
) {
694 *StringFontInfo
= NULL
;
702 If GetStringBlock find the StringId's string is not saved in the exist string block,
703 this function will create the UCS2 string block to save the string; also split the
704 skip block into two or one skip block.
706 This is a internal function.
708 @param StringPackage Hii string package instance.
709 @param StartStringId The first id in the skip block which StringId in the block.
710 @param StringId The string's id, which is unique within
712 @param BlockType Output the block type of found string block.
713 @param StringBlockAddr Output the block address of found string block.
714 @param FontBlock whether this string block has font info.
716 @retval EFI_SUCCESS The string font is outputed successfully.
717 @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block.
721 InsertLackStringBlock (
722 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
723 IN EFI_STRING_ID StartStringId
,
724 IN EFI_STRING_ID StringId
,
725 IN OUT UINT8
*BlockType
,
726 IN OUT UINT8
**StringBlockAddr
,
736 UINT32 NewUCSBlockLen
;
737 UINT8
*OldStringAddr
;
742 OldStringAddr
= *StringBlockAddr
;
744 ASSERT (*BlockType
== EFI_HII_SIBT_SKIP1
|| *BlockType
== EFI_HII_SIBT_SKIP2
);
746 // Old skip block size.
748 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
749 SkipLen
= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
750 IdCount
= *(UINT8
*)(OldStringAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
752 SkipLen
= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
753 IdCount
= *(UINT16
*)(OldStringAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
757 // New create UCS or UCS2 block size.
760 NewUCSBlockLen
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
);
762 NewUCSBlockLen
= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
765 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
767 if (StartStringId
== StringId
) {
769 // New block + [Skip block]
772 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
;
774 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
- SkipLen
;
776 } else if (StartStringId
+ IdCount
- 1 == StringId
){
778 // Skip block + New block
780 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
;
781 FrontSkipNum
= StringId
- StartStringId
;
784 // Skip block + New block + [Skip block]
786 NewBlockSize
= OldBlockSize
+ NewUCSBlockLen
+ SkipLen
;
787 FrontSkipNum
= StringId
- StartStringId
;
790 StringBlock
= (UINT8
*) AllocateZeroPool (NewBlockSize
);
791 if (StringBlock
== NULL
) {
792 return EFI_OUT_OF_RESOURCES
;
796 // Copy old block in front of skip block.
798 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldStringAddr
- StringPackage
->StringBlock
);
799 BlockPtr
= StringBlock
+ (OldStringAddr
- StringPackage
->StringBlock
);
801 if (FrontSkipNum
> 0) {
802 *BlockPtr
= *BlockType
;
803 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
804 *(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT8
) FrontSkipNum
;
806 *(UINT16
*)(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT16
) FrontSkipNum
;
812 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
814 *StringBlockAddr
= BlockPtr
;
816 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
818 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
820 BlockPtr
+= NewUCSBlockLen
;
822 if (IdCount
> FrontSkipNum
+ 1) {
823 *BlockPtr
= *BlockType
;
824 if (*BlockType
== EFI_HII_SIBT_SKIP1
) {
825 *(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT8
) (IdCount
- FrontSkipNum
- 1);
827 *(UINT16
*)(BlockPtr
+ sizeof (EFI_HII_STRING_BLOCK
)) = (UINT16
) (IdCount
- FrontSkipNum
- 1);
833 // Append a EFI_HII_SIBT_END block to the end.
835 CopyMem (BlockPtr
, OldStringAddr
+ SkipLen
, OldBlockSize
- (OldStringAddr
- StringPackage
->StringBlock
) - SkipLen
);
838 *BlockType
= EFI_HII_SIBT_STRING_UCS2_FONT
;
840 *BlockType
= EFI_HII_SIBT_STRING_UCS2
;
842 FreePool (StringPackage
->StringBlock
);
843 StringPackage
->StringBlock
= StringBlock
;
844 StringPackage
->StringPkgHdr
->Header
.Length
+= NewBlockSize
- OldBlockSize
;
850 Parse all string blocks to set a String specified by StringId.
852 This is a internal function.
854 @param Private HII database driver private structure.
855 @param StringPackage HII string package instance.
856 @param StringId The string's id, which is unique within
858 @param String Points to the new null-terminated string.
859 @param StringFontInfo Points to the input font info.
861 @retval EFI_SUCCESS The string was updated successfully.
862 @retval EFI_NOT_FOUND The string specified by StringId is not in the
864 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
865 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
867 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
873 IN HII_DATABASE_PRIVATE_DATA
*Private
,
874 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
875 IN EFI_STRING_ID StringId
,
876 IN EFI_STRING String
,
877 IN EFI_FONT_INFO
*StringFontInfo OPTIONAL
880 UINT8
*StringTextPtr
;
882 UINT8
*StringBlockAddr
;
883 UINTN StringTextOffset
;
889 HII_FONT_INFO
*LocalFont
;
890 HII_GLOBAL_FONT_INFO
*GlobalFont
;
892 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
895 EFI_STRING_ID StartStringId
;
898 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& String
!= NULL
);
899 ASSERT (Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
901 // Find the specified string block
903 Status
= FindStringBlock (
913 if (EFI_ERROR (Status
) && (BlockType
== EFI_HII_SIBT_SKIP1
|| BlockType
== EFI_HII_SIBT_SKIP2
)) {
914 Status
= InsertLackStringBlock(StringPackage
,
919 (BOOLEAN
)(StringFontInfo
!= NULL
)
921 if (EFI_ERROR (Status
)) {
924 if (StringFontInfo
!= NULL
) {
925 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
927 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
);
936 // The input StringFontInfo should exist in current database if specified.
938 if (StringFontInfo
!= NULL
) {
939 if (!IsFontInfoExisted (Private
, StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
940 return EFI_INVALID_PARAMETER
;
942 Referred
= ReferFontInfoLocally (
945 StringPackage
->FontId
,
951 StringPackage
->FontId
++;
955 // Update the FontId of the specified string block to input font info.
958 case EFI_HII_SIBT_STRING_SCSU_FONT
:
959 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
960 case EFI_HII_SIBT_STRING_UCS2_FONT
:
961 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
962 *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
)) = LocalFont
->FontId
;
966 // When modify the font info of these blocks, the block type should be updated
967 // to contain font info thus the whole structure should be revised.
968 // It is recommended to use tool to modify the block type not in the code.
970 return EFI_UNSUPPORTED
;
974 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
977 // Set the string text and font.
979 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
981 case EFI_HII_SIBT_STRING_SCSU
:
982 case EFI_HII_SIBT_STRING_SCSU_FONT
:
983 case EFI_HII_SIBT_STRINGS_SCSU
:
984 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
985 BlockSize
= OldBlockSize
+ StrLen (String
);
986 BlockSize
-= AsciiStrSize ((CHAR8
*) StringTextPtr
);
987 Block
= AllocateZeroPool (BlockSize
);
989 return EFI_OUT_OF_RESOURCES
;
992 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
993 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
995 while (*String
!= 0) {
996 *BlockPtr
++ = (CHAR8
) *String
++;
1001 TmpSize
= OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - AsciiStrSize ((CHAR8
*) StringTextPtr
);
1004 StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
),
1008 FreePool (StringPackage
->StringBlock
);
1009 StringPackage
->StringBlock
= Block
;
1010 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1013 case EFI_HII_SIBT_STRING_UCS2
:
1014 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1015 case EFI_HII_SIBT_STRINGS_UCS2
:
1016 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1018 // Use StrSize to store the size of the specified string, including the NULL
1021 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
1023 BlockSize
= OldBlockSize
+ StrSize (String
) - StringSize
;
1024 Block
= AllocateZeroPool (BlockSize
);
1025 if (Block
== NULL
) {
1026 return EFI_OUT_OF_RESOURCES
;
1029 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
1030 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
1032 CopyMem (BlockPtr
, String
, StrSize (String
));
1033 BlockPtr
+= StrSize (String
);
1037 StringTextPtr
+ StringSize
,
1038 OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - StringSize
1041 FreePool (StringPackage
->StringBlock
);
1042 StringPackage
->StringBlock
= Block
;
1043 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1047 return EFI_NOT_FOUND
;
1051 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
1052 // StringFontInfo does not exist in current string package.
1054 // This new block does not impact on the value of StringId.
1057 if (StringFontInfo
== NULL
|| Referred
) {
1061 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1062 BlockSize
= OldBlockSize
+ sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
) +
1063 StrSize (GlobalFont
->FontInfo
->FontName
);
1065 Block
= AllocateZeroPool (BlockSize
);
1066 if (Block
== NULL
) {
1067 return EFI_OUT_OF_RESOURCES
;
1071 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1072 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1073 Ext2
.Length
= (UINT16
) (BlockSize
- OldBlockSize
);
1074 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1075 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1077 *BlockPtr
= LocalFont
->FontId
;
1078 BlockPtr
+= sizeof (UINT8
);
1079 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontSize
, sizeof (UINT16
));
1080 BlockPtr
+= sizeof (UINT16
);
1081 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontStyle
, sizeof (UINT32
));
1082 BlockPtr
+= sizeof (UINT32
);
1085 GlobalFont
->FontInfo
->FontName
,
1086 StrSize (GlobalFont
->FontInfo
->FontName
)
1088 BlockPtr
+= StrSize (GlobalFont
->FontInfo
->FontName
);
1090 CopyMem (BlockPtr
, StringPackage
->StringBlock
, OldBlockSize
);
1092 FreePool (StringPackage
->StringBlock
);
1093 StringPackage
->StringBlock
= Block
;
1094 StringPackage
->StringPkgHdr
->Header
.Length
+= Ext2
.Length
;
1102 This function adds the string String to the group of strings owned by PackageList, with the
1103 specified font information StringFontInfo and returns a new string id.
1104 The new string identifier is guaranteed to be unique within the package list.
1105 That new string identifier is reserved for all languages in the package list.
1108 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1109 @param PackageList Handle of the package list where this string will
1111 @param StringId On return, contains the new strings id, which is
1112 unique within PackageList.
1113 @param Language Points to the language for the new string.
1114 @param LanguageName Points to the printable language name to associate
1115 with the passed in Language field.If LanguageName
1116 is not NULL and the string package header's
1117 LanguageName associated with a given Language is
1118 not zero, the LanguageName being passed in will
1120 @param String Points to the new null-terminated string.
1121 @param StringFontInfo Points to the new string's font information or
1122 NULL if the string should have the default system
1123 font, size and style.
1125 @retval EFI_SUCCESS The new string was added successfully.
1126 @retval EFI_NOT_FOUND The specified PackageList could not be found in
1128 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
1129 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
1131 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1138 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1139 IN EFI_HII_HANDLE PackageList
,
1140 OUT EFI_STRING_ID
*StringId
,
1141 IN CONST CHAR8
*Language
,
1142 IN CONST CHAR16
*LanguageName
, OPTIONAL
1143 IN CONST EFI_STRING String
,
1144 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1149 HII_DATABASE_PRIVATE_DATA
*Private
;
1150 HII_DATABASE_RECORD
*DatabaseRecord
;
1151 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1152 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1155 UINT32 OldBlockSize
;
1158 UINT32 Ucs2BlockSize
;
1159 UINT32 FontBlockSize
;
1160 UINT32 Ucs2FontBlockSize
;
1161 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1162 HII_FONT_INFO
*LocalFont
;
1163 HII_GLOBAL_FONT_INFO
*GlobalFont
;
1164 EFI_STRING_ID NewStringId
;
1165 EFI_STRING_ID NextStringId
;
1166 EFI_STRING_ID Index
;
1167 HII_STRING_PACKAGE_INSTANCE
*MatchStringPackage
;
1168 BOOLEAN NewStringPackageCreated
;
1171 if (This
== NULL
|| String
== NULL
|| StringId
== NULL
|| Language
== NULL
|| PackageList
== NULL
) {
1172 return EFI_INVALID_PARAMETER
;
1175 if (!IsHiiHandleValid (PackageList
)) {
1176 return EFI_NOT_FOUND
;
1179 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1183 // If StringFontInfo specify a paritcular font, it should exist in current database.
1185 if (StringFontInfo
!= NULL
) {
1186 if (!IsFontInfoExisted (Private
, (EFI_FONT_INFO
*) StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
1187 return EFI_INVALID_PARAMETER
;
1192 // Get the matching package list.
1194 PackageListNode
= NULL
;
1195 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1196 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1197 if (DatabaseRecord
->Handle
== PackageList
) {
1198 PackageListNode
= DatabaseRecord
->PackageList
;
1202 if (PackageListNode
== NULL
) {
1203 return EFI_NOT_FOUND
;
1206 Status
= EFI_SUCCESS
;
1207 NewStringPackageCreated
= FALSE
;
1210 StringPackage
= NULL
;
1211 MatchStringPackage
= NULL
;
1212 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1213 Link
!= &PackageListNode
->StringPkgHdr
;
1214 Link
= Link
->ForwardLink
1216 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1218 // Create a string block and corresponding font block if exists, then append them
1219 // to the end of the string package.
1221 Status
= FindStringBlock (
1231 if (EFI_ERROR (Status
)) {
1235 // Make sure that new StringId is same in all String Packages for the different language.
1237 if (NewStringId
!= 0 && NewStringId
!= NextStringId
) {
1239 Status
= EFI_INVALID_PARAMETER
;
1242 NewStringId
= NextStringId
;
1244 // Get the matched string package with language.
1246 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1247 MatchStringPackage
= StringPackage
;
1249 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1251 // Create a blank EFI_HII_SIBT_STRING_UCS2_BLOCK to reserve new string ID.
1253 Ucs2BlockSize
= (UINT32
) sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1255 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1256 if (StringBlock
== NULL
) {
1257 Status
= EFI_OUT_OF_RESOURCES
;
1261 // Copy original string blocks, except the EFI_HII_SIBT_END.
1263 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1265 // Create a blank EFI_HII_SIBT_STRING_UCS2 block
1267 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1268 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1269 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1272 // Append a EFI_HII_SIBT_END block to the end.
1274 *BlockPtr
= EFI_HII_SIBT_END
;
1275 FreePool (StringPackage
->StringBlock
);
1276 StringPackage
->StringBlock
= StringBlock
;
1277 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1278 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1281 if (NewStringId
== 0) {
1283 // No string package is found.
1284 // Create new string package. StringId 1 is reserved for Language Name string.
1291 *StringId
= (EFI_STRING_ID
) (NewStringId
+ 1);
1294 if (MatchStringPackage
!= NULL
) {
1295 StringPackage
= MatchStringPackage
;
1298 // LanguageName is required to create a new string package.
1300 if (LanguageName
== NULL
) {
1301 Status
= EFI_INVALID_PARAMETER
;
1305 StringPackage
= AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE
));
1306 if (StringPackage
== NULL
) {
1307 Status
= EFI_OUT_OF_RESOURCES
;
1311 StringPackage
->Signature
= HII_STRING_PACKAGE_SIGNATURE
;
1312 StringPackage
->MaxStringId
= *StringId
;
1313 StringPackage
->FontId
= 0;
1314 InitializeListHead (&StringPackage
->FontInfoList
);
1317 // Fill in the string package header
1319 HeaderSize
= (UINT32
) (AsciiStrSize ((CHAR8
*) Language
) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR
));
1320 StringPackage
->StringPkgHdr
= AllocateZeroPool (HeaderSize
);
1321 if (StringPackage
->StringPkgHdr
== NULL
) {
1322 FreePool (StringPackage
);
1323 Status
= EFI_OUT_OF_RESOURCES
;
1326 StringPackage
->StringPkgHdr
->Header
.Type
= EFI_HII_PACKAGE_STRINGS
;
1327 StringPackage
->StringPkgHdr
->HdrSize
= HeaderSize
;
1328 StringPackage
->StringPkgHdr
->StringInfoOffset
= HeaderSize
;
1329 CopyMem (StringPackage
->StringPkgHdr
->LanguageWindow
, mLanguageWindow
, 16 * sizeof (CHAR16
));
1330 StringPackage
->StringPkgHdr
->LanguageName
= 1;
1331 AsciiStrCpy (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
);
1334 // Calculate the length of the string blocks, including string block to record
1335 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1337 Ucs2BlockSize
= (UINT32
) (StrSize ((CHAR16
*) LanguageName
) +
1338 (*StringId
- 1) * sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
));
1340 BlockSize
= Ucs2BlockSize
+ sizeof (EFI_HII_SIBT_END_BLOCK
);
1341 StringPackage
->StringBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
1342 if (StringPackage
->StringBlock
== NULL
) {
1343 FreePool (StringPackage
->StringPkgHdr
);
1344 FreePool (StringPackage
);
1345 Status
= EFI_OUT_OF_RESOURCES
;
1350 // Insert the string block of printable language full name
1352 BlockPtr
= StringPackage
->StringBlock
;
1353 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1354 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1355 CopyMem (BlockPtr
, (EFI_STRING
) LanguageName
, StrSize ((EFI_STRING
) LanguageName
));
1356 BlockPtr
+= StrSize ((EFI_STRING
) LanguageName
);
1357 for (Index
= 2; Index
<= *StringId
- 1; Index
++) {
1358 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1359 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1362 // Insert the end block
1364 *BlockPtr
= EFI_HII_SIBT_END
;
1367 // Append this string package node to string package array in this package list.
1369 StringPackage
->StringPkgHdr
->Header
.Length
= HeaderSize
+ BlockSize
;
1370 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
;
1371 InsertTailList (&PackageListNode
->StringPkgHdr
, &StringPackage
->StringEntry
);
1372 NewStringPackageCreated
= TRUE
;
1375 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1377 if (StringFontInfo
== NULL
) {
1379 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1381 Ucs2BlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
)
1384 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1385 if (StringBlock
== NULL
) {
1386 Status
= EFI_OUT_OF_RESOURCES
;
1390 // Copy original string blocks, except the EFI_HII_SIBT_END.
1392 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1394 // Create a EFI_HII_SIBT_STRING_UCS2 block
1396 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1397 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1398 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1399 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1400 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1403 // Append a EFI_HII_SIBT_END block to the end.
1405 *BlockPtr
= EFI_HII_SIBT_END
;
1406 FreePool (StringPackage
->StringBlock
);
1407 StringPackage
->StringBlock
= StringBlock
;
1408 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1409 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1413 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1414 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1415 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1416 // _UCS2_FONT block.
1418 Ucs2FontBlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) -
1420 if (ReferFontInfoLocally (Private
, StringPackage
, StringPackage
->FontId
, FALSE
, GlobalFont
, &LocalFont
)) {
1422 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1424 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2FontBlockSize
);
1425 if (StringBlock
== NULL
) {
1426 Status
= EFI_OUT_OF_RESOURCES
;
1430 // Copy original string blocks, except the EFI_HII_SIBT_END.
1432 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1434 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1436 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1437 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1438 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1439 *BlockPtr
= LocalFont
->FontId
;
1440 BlockPtr
+= sizeof (UINT8
);
1441 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1442 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1445 // Append a EFI_HII_SIBT_END block to the end.
1447 *BlockPtr
= EFI_HII_SIBT_END
;
1448 FreePool (StringPackage
->StringBlock
);
1449 StringPackage
->StringBlock
= StringBlock
;
1450 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2FontBlockSize
;
1451 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2FontBlockSize
;
1455 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1456 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1457 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1459 FontBlockSize
= (UINT32
) (StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
) +
1460 sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
));
1461 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ FontBlockSize
+ Ucs2FontBlockSize
);
1462 if (StringBlock
== NULL
) {
1463 Status
= EFI_OUT_OF_RESOURCES
;
1467 // Copy original string blocks, except the EFI_HII_SIBT_END.
1469 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1472 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1473 // package instance for future reference.
1475 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1477 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1478 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1479 Ext2
.Length
= (UINT16
) FontBlockSize
;
1480 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1481 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1483 *BlockPtr
= LocalFont
->FontId
;
1484 BlockPtr
+= sizeof (UINT8
);
1485 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontSize
, sizeof (UINT16
));
1486 BlockPtr
+= sizeof (UINT16
);
1487 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontStyle
, sizeof (EFI_HII_FONT_STYLE
));
1488 BlockPtr
+= sizeof (EFI_HII_FONT_STYLE
);
1491 &((EFI_FONT_INFO
*) StringFontInfo
)->FontName
,
1492 StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
)
1494 BlockPtr
+= StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
);
1496 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1498 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1499 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1500 *BlockPtr
= LocalFont
->FontId
;
1501 BlockPtr
+= sizeof (UINT8
);
1502 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1503 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1506 // Append a EFI_HII_SIBT_END block to the end.
1508 *BlockPtr
= EFI_HII_SIBT_END
;
1509 FreePool (StringPackage
->StringBlock
);
1510 StringPackage
->StringBlock
= StringBlock
;
1511 StringPackage
->StringPkgHdr
->Header
.Length
+= FontBlockSize
+ Ucs2FontBlockSize
;
1512 PackageListNode
->PackageListHdr
.PackageLength
+= FontBlockSize
+ Ucs2FontBlockSize
;
1515 // Increase the FontId to make it unique since we already add
1516 // a EFI_HII_SIBT_FONT block to this string package.
1518 StringPackage
->FontId
++;
1523 if (!EFI_ERROR (Status
) && NewStringPackageCreated
) {
1525 // Trigger any registered notification function for new string package
1527 Status
= InvokeRegisteredFunction (
1529 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
1530 (VOID
*) StringPackage
,
1531 EFI_HII_PACKAGE_STRINGS
,
1536 if (!EFI_ERROR (Status
)) {
1538 // Update MaxString Id to new StringId
1540 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1541 Link
!= &PackageListNode
->StringPkgHdr
;
1542 Link
= Link
->ForwardLink
1544 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1545 StringPackage
->MaxStringId
= *StringId
;
1547 } else if (NewStringPackageCreated
) {
1549 // Free the allocated new string Package when new string can't be added.
1551 RemoveEntryList (&StringPackage
->StringEntry
);
1552 FreePool (StringPackage
->StringBlock
);
1553 FreePool (StringPackage
->StringPkgHdr
);
1554 FreePool (StringPackage
);
1562 This function retrieves the string specified by StringId which is associated
1563 with the specified PackageList in the language Language and copies it into
1564 the buffer specified by String.
1566 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1567 @param Language Points to the language for the retrieved string.
1568 @param PackageList The package list in the HII database to search for
1569 the specified string.
1570 @param StringId The string's id, which is unique within
1572 @param String Points to the new null-terminated string.
1573 @param StringSize On entry, points to the size of the buffer pointed
1574 to by String, in bytes. On return, points to the
1575 length of the string, in bytes.
1576 @param StringFontInfo If not NULL, points to the string's font
1577 information. It's caller's responsibility to free
1580 @retval EFI_SUCCESS The string was returned successfully.
1581 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1582 @retval EFI_NOT_FOUND The string specified by StringId is available but
1583 not in the specified language.
1584 The specified PackageList is not in the database.
1585 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but
1586 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1588 @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.
1589 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1596 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1597 IN CONST CHAR8
*Language
,
1598 IN EFI_HII_HANDLE PackageList
,
1599 IN EFI_STRING_ID StringId
,
1600 OUT EFI_STRING String
,
1601 IN OUT UINTN
*StringSize
,
1602 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
1607 HII_DATABASE_PRIVATE_DATA
*Private
;
1608 HII_DATABASE_RECORD
*DatabaseRecord
;
1609 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1610 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1612 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || StringSize
== NULL
|| PackageList
== NULL
) {
1613 return EFI_INVALID_PARAMETER
;
1616 if (String
== NULL
&& *StringSize
!= 0) {
1617 return EFI_INVALID_PARAMETER
;
1620 if (!IsHiiHandleValid (PackageList
)) {
1621 return EFI_NOT_FOUND
;
1624 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1625 PackageListNode
= NULL
;
1627 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1628 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1629 if (DatabaseRecord
->Handle
== PackageList
) {
1630 PackageListNode
= DatabaseRecord
->PackageList
;
1635 if (PackageListNode
!= NULL
) {
1637 // First search: to match the StringId in the specified language.
1639 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1640 Link
!= &PackageListNode
->StringPkgHdr
;
1641 Link
= Link
->ForwardLink
1643 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1644 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1645 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1646 if (Status
!= EFI_NOT_FOUND
) {
1652 // Second search: to match the StringId in other available languages if exist.
1654 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1655 Link
!= &PackageListNode
->StringPkgHdr
;
1656 Link
= Link
->ForwardLink
1658 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1659 Status
= GetStringWorker (Private
, StringPackage
, StringId
, NULL
, NULL
, NULL
);
1660 if (!EFI_ERROR (Status
)) {
1661 return EFI_INVALID_LANGUAGE
;
1666 return EFI_NOT_FOUND
;
1672 This function updates the string specified by StringId in the specified PackageList to the text
1673 specified by String and, optionally, the font information specified by StringFontInfo.
1675 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1676 @param PackageList The package list containing the strings.
1677 @param StringId The string's id, which is unique within
1679 @param Language Points to the language for the updated string.
1680 @param String Points to the new null-terminated string.
1681 @param StringFontInfo Points to the string's font information or NULL if
1682 the string font information is not changed.
1684 @retval EFI_SUCCESS The string was updated successfully.
1685 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1687 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1688 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1690 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1697 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1698 IN EFI_HII_HANDLE PackageList
,
1699 IN EFI_STRING_ID StringId
,
1700 IN CONST CHAR8
*Language
,
1701 IN CONST EFI_STRING String
,
1702 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1707 HII_DATABASE_PRIVATE_DATA
*Private
;
1708 HII_DATABASE_RECORD
*DatabaseRecord
;
1709 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1710 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1711 UINT32 OldPackageLen
;
1713 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || String
== NULL
|| PackageList
== NULL
) {
1714 return EFI_INVALID_PARAMETER
;
1717 if (!IsHiiHandleValid (PackageList
)) {
1718 return EFI_NOT_FOUND
;
1721 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1722 PackageListNode
= NULL
;
1724 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1725 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1726 if (DatabaseRecord
->Handle
== PackageList
) {
1727 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1731 if (PackageListNode
!= NULL
) {
1732 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1733 Link
!= &PackageListNode
->StringPkgHdr
;
1734 Link
= Link
->ForwardLink
1736 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1737 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1738 OldPackageLen
= StringPackage
->StringPkgHdr
->Header
.Length
;
1739 Status
= SetStringWorker (
1743 (EFI_STRING
) String
,
1744 (EFI_FONT_INFO
*) StringFontInfo
1746 if (EFI_ERROR (Status
)) {
1749 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
- OldPackageLen
;
1755 return EFI_NOT_FOUND
;
1761 This function returns the list of supported languages, in the format specified
1762 in Appendix M of UEFI 2.1 spec.
1764 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1765 @param PackageList The package list to examine.
1766 @param Languages Points to the buffer to hold the returned string.
1767 @param LanguagesSize On entry, points to the size of the buffer pointed
1768 to by Languages, in bytes. On return, points to
1769 the length of Languages, in bytes.
1771 @retval EFI_SUCCESS The languages were returned successfully.
1772 @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.
1773 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1774 supported languages. LanguageSize is updated to
1775 contain the required size.
1776 @retval EFI_NOT_FOUND Could not find string package in specified
1783 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1784 IN EFI_HII_HANDLE PackageList
,
1785 IN OUT CHAR8
*Languages
,
1786 IN OUT UINTN
*LanguagesSize
1790 HII_DATABASE_PRIVATE_DATA
*Private
;
1791 HII_DATABASE_RECORD
*DatabaseRecord
;
1792 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1793 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1796 if (This
== NULL
|| Languages
== NULL
|| LanguagesSize
== NULL
|| PackageList
== NULL
) {
1797 return EFI_INVALID_PARAMETER
;
1799 if (!IsHiiHandleValid (PackageList
)) {
1800 return EFI_NOT_FOUND
;
1803 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1805 PackageListNode
= NULL
;
1806 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1807 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1808 if (DatabaseRecord
->Handle
== PackageList
) {
1809 PackageListNode
= DatabaseRecord
->PackageList
;
1813 if (PackageListNode
== NULL
) {
1814 return EFI_NOT_FOUND
;
1818 // Search the languages in the specified packagelist.
1821 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1822 Link
!= &PackageListNode
->StringPkgHdr
;
1823 Link
= Link
->ForwardLink
1825 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1826 ResultSize
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1827 if (ResultSize
<= *LanguagesSize
) {
1828 AsciiStrCpy (Languages
, StringPackage
->StringPkgHdr
->Language
);
1829 Languages
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1830 *(Languages
- 1) = L
';';
1833 if (ResultSize
== 0) {
1834 return EFI_NOT_FOUND
;
1837 if (*LanguagesSize
< ResultSize
) {
1838 *LanguagesSize
= ResultSize
;
1839 return EFI_BUFFER_TOO_SMALL
;
1842 *(Languages
- 1) = 0;
1848 Each string package has associated with it a single primary language and zero
1849 or more secondary languages. This routine returns the secondary languages
1850 associated with a package list.
1852 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1853 @param PackageList The package list to examine.
1854 @param FirstLanguage Points to the primary language.
1855 @param SecondaryLanguages Points to the buffer to hold the returned list of
1856 secondary languages for the specified
1857 FirstLanguage. If there are no secondary
1858 languages, the function returns successfully, but
1859 this is set to NULL.
1860 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed
1861 to by SecondaryLanguages, in bytes. On return,
1862 points to the length of SecondaryLanguages in bytes.
1864 @retval EFI_SUCCESS Secondary languages were correctly returned.
1865 @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or
1866 SecondaryLanguagesSize was NULL.
1867 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is
1868 too small to hold the returned information.
1869 SecondLanguageSize is updated to hold the size of
1870 the buffer required.
1871 @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not
1872 present in the specified package list.
1873 @retval EFI_NOT_FOUND The specified PackageList is not in the Database.
1878 HiiGetSecondaryLanguages (
1879 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1880 IN EFI_HII_HANDLE PackageList
,
1881 IN CONST CHAR8
*FirstLanguage
,
1882 IN OUT CHAR8
*SecondaryLanguages
,
1883 IN OUT UINTN
*SecondaryLanguagesSize
1888 HII_DATABASE_PRIVATE_DATA
*Private
;
1889 HII_DATABASE_RECORD
*DatabaseRecord
;
1890 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1891 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1895 if (This
== NULL
|| PackageList
== NULL
|| FirstLanguage
== NULL
) {
1896 return EFI_INVALID_PARAMETER
;
1898 if (SecondaryLanguages
== NULL
|| SecondaryLanguagesSize
== NULL
) {
1899 return EFI_INVALID_PARAMETER
;
1901 if (!IsHiiHandleValid (PackageList
)) {
1902 return EFI_NOT_FOUND
;
1905 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1907 PackageListNode
= NULL
;
1908 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1909 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1910 if (DatabaseRecord
->Handle
== PackageList
) {
1911 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1915 if (PackageListNode
== NULL
) {
1916 return EFI_NOT_FOUND
;
1921 for (Link1
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1922 Link1
!= &PackageListNode
->StringPkgHdr
;
1923 Link1
= Link1
->ForwardLink
1925 StringPackage
= CR (Link1
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1926 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) FirstLanguage
)) {
1927 Languages
= StringPackage
->StringPkgHdr
->Language
;
1929 // Language is a series of ';' terminated strings, first one is primary
1930 // language and following with other secondary languages or NULL if no
1931 // secondary languages any more.
1933 Languages
= AsciiStrStr (Languages
, ";");
1934 if (Languages
== NULL
) {
1939 ResultSize
= AsciiStrSize (Languages
);
1940 if (ResultSize
<= *SecondaryLanguagesSize
) {
1941 AsciiStrCpy (SecondaryLanguages
, Languages
);
1943 *SecondaryLanguagesSize
= ResultSize
;
1944 return EFI_BUFFER_TOO_SMALL
;
1951 return EFI_INVALID_LANGUAGE
;
1955 Compare whether two names of languages are identical.
1957 @param Language1 Name of language 1 from StringPackage
1958 @param Language2 Name of language 2 to be compared with language 1.
1961 @retval FALSE not same
1965 HiiCompareLanguage (
1966 IN CHAR8
*Language1
,
1973 // Compare the Primary Language in Language1 to Language2
1975 for (Index
= 0; Language1
[Index
] != 0 && Language1
[Index
] != ';'; Index
++) {
1976 if (Language1
[Index
] != Language2
[Index
]) {
1978 // Return FALSE if any characters are different.
1985 // Only return TRUE if Language2[Index] is a Null-terminator which means
1986 // the Primary Language in Language1 is the same length as Language2. If
1987 // Language2[Index] is not a Null-terminator, then Language2 is longer than
1988 // the Primary Language in Language1, and FALSE must be returned.
1990 return (Language2
[Index
] == 0);