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 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "HiiDatabase.h"
14 CHAR16 mLanguageWindow
[16] = {
15 0x0000, 0x0080, 0x0100, 0x0300,
16 0x2000, 0x2080, 0x2100, 0x3000,
17 0x0080, 0x00C0, 0x0400, 0x0600,
18 0x0900, 0x3040, 0x30A0, 0xFF00
23 This function checks whether a global font info is referred by local
24 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
25 a HII_FONT_INFO to refer it locally.
27 This is a internal function.
30 @param Private Hii database private structure.
31 @param StringPackage HII string package instance.
32 @param FontId Font identifer, which must be unique within the string package.
33 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
34 the same EFI_FONT_INFO is permitted. Otherwise it
36 @param GlobalFontInfo Input a global font info which specify a
38 @param LocalFontInfo Output a local font info which refers to a
41 @retval TRUE Already referred before calling this function.
42 @retval FALSE Not referred before calling this function.
46 ReferFontInfoLocally (
47 IN HII_DATABASE_PRIVATE_DATA
*Private
,
48 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
50 IN BOOLEAN DuplicateEnable
,
51 IN HII_GLOBAL_FONT_INFO
*GlobalFontInfo
,
52 OUT HII_FONT_INFO
**LocalFontInfo
55 HII_FONT_INFO
*LocalFont
;
58 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& GlobalFontInfo
!= NULL
&& LocalFontInfo
!= NULL
);
60 if (!DuplicateEnable
) {
61 for (Link
= StringPackage
->FontInfoList
.ForwardLink
;
62 Link
!= &StringPackage
->FontInfoList
;
63 Link
= Link
->ForwardLink
65 LocalFont
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
66 if (LocalFont
->GlobalEntry
== &GlobalFontInfo
->Entry
) {
68 // Already referred by local font info list, return directly.
70 *LocalFontInfo
= LocalFont
;
75 // FontId identifies EFI_FONT_INFO in local string package uniquely.
76 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
77 // EFI_FONT_INFO uniquely in whole hii database.
79 LocalFont
= (HII_FONT_INFO
*) AllocateZeroPool (sizeof (HII_FONT_INFO
));
80 ASSERT (LocalFont
!= NULL
);
82 LocalFont
->Signature
= HII_FONT_INFO_SIGNATURE
;
83 LocalFont
->FontId
= FontId
;
84 LocalFont
->GlobalEntry
= &GlobalFontInfo
->Entry
;
85 InsertTailList (&StringPackage
->FontInfoList
, &LocalFont
->Entry
);
87 *LocalFontInfo
= LocalFont
;
93 Convert Ascii string text to unicode string test.
95 This is a internal function.
98 @param StringDest Buffer to store the string text. If it is NULL,
99 only the size will be returned.
100 @param StringSrc Points to current null-terminated string.
101 @param BufferSize Length of the buffer.
103 @retval EFI_SUCCESS The string text was outputted successfully.
104 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
105 text. BufferSize is updated to the required buffer
110 ConvertToUnicodeText (
111 OUT EFI_STRING StringDest
,
113 IN OUT UINTN
*BufferSize
119 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
121 StringSize
= AsciiStrSize (StringSrc
) * 2;
122 if (*BufferSize
< StringSize
|| StringDest
== NULL
) {
123 *BufferSize
= StringSize
;
124 return EFI_BUFFER_TOO_SMALL
;
127 for (Index
= 0; Index
< AsciiStrLen (StringSrc
); Index
++) {
128 StringDest
[Index
] = (CHAR16
) StringSrc
[Index
];
131 StringDest
[Index
] = 0;
137 Calculate the size of StringSrc and output it. If StringDest is not NULL,
138 copy string text from src to dest.
140 This is a internal function.
142 @param StringDest Buffer to store the string text. If it is NULL,
143 only the size will be returned.
144 @param StringSrc Points to current null-terminated string.
145 @param BufferSize Length of the buffer.
147 @retval EFI_SUCCESS The string text was outputted successfully.
148 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
149 text. BufferSize is updated to the required buffer
154 GetUnicodeStringTextOrSize (
155 OUT EFI_STRING StringDest
, OPTIONAL
157 IN OUT UINTN
*BufferSize
163 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
165 StringSize
= sizeof (CHAR16
);
166 StringPtr
= StringSrc
;
167 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
168 StringSize
+= sizeof (CHAR16
);
169 StringPtr
+= sizeof (CHAR16
);
172 if (*BufferSize
< StringSize
) {
173 *BufferSize
= StringSize
;
174 return EFI_BUFFER_TOO_SMALL
;
176 if (StringDest
!= NULL
) {
177 CopyMem (StringDest
, StringSrc
, StringSize
);
180 *BufferSize
= StringSize
;
186 Copy string font info to a buffer.
188 This is a internal function.
190 @param StringPackage Hii string package instance.
191 @param FontId Font identifier which is unique in a string
193 @param StringFontInfo Buffer to record the output font info. It's
194 caller's responsibility to free this buffer.
196 @retval EFI_SUCCESS The string font is outputted successfully.
197 @retval EFI_NOT_FOUND The specified font id does not exist.
202 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
204 OUT EFI_FONT_INFO
**StringFontInfo
208 HII_FONT_INFO
*FontInfo
;
209 HII_GLOBAL_FONT_INFO
*GlobalFont
;
211 ASSERT (StringFontInfo
!= NULL
&& StringPackage
!= NULL
);
213 for (Link
= StringPackage
->FontInfoList
.ForwardLink
; Link
!= &StringPackage
->FontInfoList
; Link
= Link
->ForwardLink
) {
214 FontInfo
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
215 if (FontInfo
->FontId
== FontId
) {
216 GlobalFont
= CR (FontInfo
->GlobalEntry
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
217 *StringFontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (GlobalFont
->FontInfoSize
);
218 if (*StringFontInfo
== NULL
) {
219 return EFI_OUT_OF_RESOURCES
;
221 CopyMem (*StringFontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
226 return EFI_NOT_FOUND
;
231 Parse all string blocks to find a String block specified by StringId.
232 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
233 within this string package and backup its information. If LastStringId is
234 specified, the string id of last string block will also be output.
235 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_STRING).
237 @param Private Hii database private structure.
238 @param StringPackage Hii string package instance.
239 @param StringId The string's id, which is unique within
241 @param BlockType Output the block type of found string block.
242 @param StringBlockAddr Output the block address of found string block.
243 @param StringTextOffset Offset, relative to the found block address, of
244 the string text information.
245 @param LastStringId Output the last string id when StringId = 0 or StringId = -1.
246 @param StartStringId The first id in the skip block which StringId in the block.
248 @retval EFI_SUCCESS The string text and font is retrieved
250 @retval EFI_NOT_FOUND The specified text or font info can not be found
252 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
258 IN HII_DATABASE_PRIVATE_DATA
*Private
,
259 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
260 IN EFI_STRING_ID StringId
,
261 OUT UINT8
*BlockType
, OPTIONAL
262 OUT UINT8
**StringBlockAddr
, OPTIONAL
263 OUT UINTN
*StringTextOffset
, OPTIONAL
264 OUT EFI_STRING_ID
*LastStringId
, OPTIONAL
265 OUT EFI_STRING_ID
*StartStringId OPTIONAL
269 EFI_STRING_ID CurrentStringId
;
272 UINT8
*StringTextPtr
;
274 HII_FONT_INFO
*LocalFont
;
275 EFI_FONT_INFO
*FontInfo
;
276 HII_GLOBAL_FONT_INFO
*GlobalFont
;
280 EFI_HII_FONT_STYLE FontStyle
;
283 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
289 ASSERT (StringPackage
!= NULL
);
290 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
295 if (StringId
!= (EFI_STRING_ID
) (-1) && StringId
!= 0) {
296 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
297 if (StringId
> StringPackage
->MaxStringId
) {
298 return EFI_NOT_FOUND
;
301 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
302 if (StringId
== 0 && LastStringId
!= NULL
) {
303 *LastStringId
= StringPackage
->MaxStringId
;
308 ZeroMem (&Zero
, sizeof (CHAR16
));
311 // Parse the string blocks to get the string text and font.
313 BlockHdr
= StringPackage
->StringBlock
;
316 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
318 case EFI_HII_SIBT_STRING_SCSU
:
319 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
320 StringTextPtr
= BlockHdr
+ Offset
;
321 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
325 case EFI_HII_SIBT_STRING_SCSU_FONT
:
326 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
327 StringTextPtr
= BlockHdr
+ Offset
;
328 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
332 case EFI_HII_SIBT_STRINGS_SCSU
:
333 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
334 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
));
335 BlockSize
+= StringTextPtr
- BlockHdr
;
337 for (Index
= 0; Index
< StringCount
; Index
++) {
338 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
339 if (CurrentStringId
== StringId
) {
340 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
341 *BlockType
= *BlockHdr
;
342 *StringBlockAddr
= BlockHdr
;
343 *StringTextOffset
= StringTextPtr
- BlockHdr
;
346 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
351 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
354 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
357 StringTextPtr
= (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
));
358 BlockSize
+= StringTextPtr
- BlockHdr
;
360 for (Index
= 0; Index
< StringCount
; Index
++) {
361 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
362 if (CurrentStringId
== StringId
) {
363 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
364 *BlockType
= *BlockHdr
;
365 *StringBlockAddr
= BlockHdr
;
366 *StringTextOffset
= StringTextPtr
- BlockHdr
;
369 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
374 case EFI_HII_SIBT_STRING_UCS2
:
375 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
376 StringTextPtr
= BlockHdr
+ Offset
;
378 // Use StringSize to store the size of the specified string, including the NULL
381 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
382 BlockSize
+= Offset
+ StringSize
;
386 case EFI_HII_SIBT_STRING_UCS2_FONT
:
387 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
388 StringTextPtr
= BlockHdr
+ Offset
;
390 // Use StrSize to store the size of the specified string, including the NULL
393 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
394 BlockSize
+= Offset
+ StringSize
;
398 case EFI_HII_SIBT_STRINGS_UCS2
:
399 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
400 StringTextPtr
= BlockHdr
+ Offset
;
402 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
403 for (Index
= 0; Index
< StringCount
; Index
++) {
404 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
405 BlockSize
+= StringSize
;
406 if (CurrentStringId
== StringId
) {
407 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
408 *BlockType
= *BlockHdr
;
409 *StringBlockAddr
= BlockHdr
;
410 *StringTextOffset
= StringTextPtr
- BlockHdr
;
413 StringTextPtr
= StringTextPtr
+ StringSize
;
418 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
419 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
420 StringTextPtr
= BlockHdr
+ Offset
;
424 (UINT8
*)((UINTN
)BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
)),
427 for (Index
= 0; Index
< StringCount
; Index
++) {
428 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
429 BlockSize
+= StringSize
;
430 if (CurrentStringId
== StringId
) {
431 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
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
) (*(UINT8
*)((UINTN
)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 (UINT8
*)((UINTN
)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
));
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 (UINT8
*)((UINTN
)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) && LastStringId
!= NULL
) {
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 outputted 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
;
899 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& String
!= NULL
);
900 ASSERT (Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
902 // Find the specified string block
904 Status
= FindStringBlock (
914 if (EFI_ERROR (Status
) && (BlockType
== EFI_HII_SIBT_SKIP1
|| BlockType
== EFI_HII_SIBT_SKIP2
)) {
915 Status
= InsertLackStringBlock(StringPackage
,
920 (BOOLEAN
)(StringFontInfo
!= NULL
)
922 if (EFI_ERROR (Status
)) {
925 if (StringFontInfo
!= NULL
) {
926 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
928 StringTextOffset
= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
);
937 // The input StringFontInfo should exist in current database if specified.
939 if (StringFontInfo
!= NULL
) {
940 if (!IsFontInfoExisted (Private
, StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
941 return EFI_INVALID_PARAMETER
;
943 Referred
= ReferFontInfoLocally (
946 StringPackage
->FontId
,
952 StringPackage
->FontId
++;
956 // Update the FontId of the specified string block to input font info.
959 case EFI_HII_SIBT_STRING_SCSU_FONT
:
960 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
961 case EFI_HII_SIBT_STRING_UCS2_FONT
:
962 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
963 *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
)) = LocalFont
->FontId
;
967 // When modify the font info of these blocks, the block type should be updated
968 // to contain font info thus the whole structure should be revised.
969 // It is recommended to use tool to modify the block type not in the code.
971 return EFI_UNSUPPORTED
;
975 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
978 // Set the string text and font.
980 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
982 case EFI_HII_SIBT_STRING_SCSU
:
983 case EFI_HII_SIBT_STRING_SCSU_FONT
:
984 case EFI_HII_SIBT_STRINGS_SCSU
:
985 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
986 BlockSize
= OldBlockSize
+ StrLen (String
);
987 BlockSize
-= AsciiStrSize ((CHAR8
*) StringTextPtr
);
988 Block
= AllocateZeroPool (BlockSize
);
990 return EFI_OUT_OF_RESOURCES
;
993 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
994 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
996 while (*String
!= 0) {
997 *BlockPtr
++ = (CHAR8
) *String
++;
1002 TmpSize
= OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - AsciiStrSize ((CHAR8
*) StringTextPtr
);
1005 StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
),
1009 FreePool (StringPackage
->StringBlock
);
1010 StringPackage
->StringBlock
= Block
;
1011 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1014 case EFI_HII_SIBT_STRING_UCS2
:
1015 case EFI_HII_SIBT_STRING_UCS2_FONT
:
1016 case EFI_HII_SIBT_STRINGS_UCS2
:
1017 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
1019 // Use StrSize to store the size of the specified string, including the NULL
1022 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
1024 BlockSize
= OldBlockSize
+ StrSize (String
) - StringSize
;
1025 Block
= AllocateZeroPool (BlockSize
);
1026 if (Block
== NULL
) {
1027 return EFI_OUT_OF_RESOURCES
;
1030 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
1031 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
1033 CopyMem (BlockPtr
, String
, StrSize (String
));
1034 BlockPtr
+= StrSize (String
);
1038 StringTextPtr
+ StringSize
,
1039 OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - StringSize
1042 FreePool (StringPackage
->StringBlock
);
1043 StringPackage
->StringBlock
= Block
;
1044 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
1048 return EFI_NOT_FOUND
;
1052 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
1053 // StringFontInfo does not exist in current string package.
1055 // This new block does not impact on the value of StringId.
1058 if (StringFontInfo
== NULL
|| Referred
) {
1062 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1063 BlockSize
= OldBlockSize
+ sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
) +
1064 StrSize (GlobalFont
->FontInfo
->FontName
);
1066 Block
= AllocateZeroPool (BlockSize
);
1067 if (Block
== NULL
) {
1068 return EFI_OUT_OF_RESOURCES
;
1072 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1073 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1074 Ext2
.Length
= (UINT16
) (BlockSize
- OldBlockSize
);
1075 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1076 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1078 *BlockPtr
= LocalFont
->FontId
;
1080 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontSize
, sizeof (UINT16
));
1081 BlockPtr
+= sizeof (UINT16
);
1082 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontStyle
, sizeof (UINT32
));
1083 BlockPtr
+= sizeof (UINT32
);
1086 GlobalFont
->FontInfo
->FontName
,
1087 StrSize (GlobalFont
->FontInfo
->FontName
)
1089 BlockPtr
+= StrSize (GlobalFont
->FontInfo
->FontName
);
1091 CopyMem (BlockPtr
, StringPackage
->StringBlock
, OldBlockSize
);
1093 FreePool (StringPackage
->StringBlock
);
1094 StringPackage
->StringBlock
= Block
;
1095 StringPackage
->StringPkgHdr
->Header
.Length
+= Ext2
.Length
;
1103 This function adds the string String to the group of strings owned by PackageList, with the
1104 specified font information StringFontInfo and returns a new string id.
1105 The new string identifier is guaranteed to be unique within the package list.
1106 That new string identifier is reserved for all languages in the package list.
1109 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1110 @param PackageList Handle of the package list where this string will
1112 @param StringId On return, contains the new strings id, which is
1113 unique within PackageList.
1114 @param Language Points to the language for the new string.
1115 @param LanguageName Points to the printable language name to associate
1116 with the passed in Language field.If LanguageName
1117 is not NULL and the string package header's
1118 LanguageName associated with a given Language is
1119 not zero, the LanguageName being passed in will
1121 @param String Points to the new null-terminated string.
1122 @param StringFontInfo Points to the new string's font information or
1123 NULL if the string should have the default system
1124 font, size and style.
1126 @retval EFI_SUCCESS The new string was added successfully.
1127 @retval EFI_NOT_FOUND The specified PackageList could not be found in
1129 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
1130 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
1132 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1139 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1140 IN EFI_HII_HANDLE PackageList
,
1141 OUT EFI_STRING_ID
*StringId
,
1142 IN CONST CHAR8
*Language
,
1143 IN CONST CHAR16
*LanguageName
, OPTIONAL
1144 IN CONST EFI_STRING String
,
1145 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1150 HII_DATABASE_PRIVATE_DATA
*Private
;
1151 HII_DATABASE_RECORD
*DatabaseRecord
;
1152 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1153 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1156 UINT32 OldBlockSize
;
1159 UINT32 Ucs2BlockSize
;
1160 UINT32 FontBlockSize
;
1161 UINT32 Ucs2FontBlockSize
;
1162 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
1163 HII_FONT_INFO
*LocalFont
;
1164 HII_GLOBAL_FONT_INFO
*GlobalFont
;
1165 EFI_STRING_ID NewStringId
;
1166 EFI_STRING_ID NextStringId
;
1167 EFI_STRING_ID Index
;
1168 HII_STRING_PACKAGE_INSTANCE
*MatchStringPackage
;
1169 BOOLEAN NewStringPackageCreated
;
1172 if (This
== NULL
|| String
== NULL
|| StringId
== NULL
|| Language
== NULL
|| PackageList
== NULL
) {
1173 return EFI_INVALID_PARAMETER
;
1176 if (!IsHiiHandleValid (PackageList
)) {
1177 return EFI_NOT_FOUND
;
1180 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1184 // If StringFontInfo specify a paritcular font, it should exist in current database.
1186 if (StringFontInfo
!= NULL
) {
1187 if (!IsFontInfoExisted (Private
, (EFI_FONT_INFO
*) StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
1188 return EFI_INVALID_PARAMETER
;
1193 // Get the matching package list.
1195 PackageListNode
= NULL
;
1196 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1197 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1198 if (DatabaseRecord
->Handle
== PackageList
) {
1199 PackageListNode
= DatabaseRecord
->PackageList
;
1203 if (PackageListNode
== NULL
) {
1204 return EFI_NOT_FOUND
;
1207 EfiAcquireLock (&mHiiDatabaseLock
);
1209 Status
= EFI_SUCCESS
;
1210 NewStringPackageCreated
= FALSE
;
1213 StringPackage
= NULL
;
1214 MatchStringPackage
= NULL
;
1215 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1216 Link
!= &PackageListNode
->StringPkgHdr
;
1217 Link
= Link
->ForwardLink
1219 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1221 // Create a string block and corresponding font block if exists, then append them
1222 // to the end of the string package.
1224 Status
= FindStringBlock (
1234 if (EFI_ERROR (Status
)) {
1238 // Make sure that new StringId is same in all String Packages for the different language.
1240 if (NewStringId
!= 0 && NewStringId
!= NextStringId
) {
1242 Status
= EFI_INVALID_PARAMETER
;
1245 NewStringId
= NextStringId
;
1247 // Get the matched string package with language.
1249 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1250 MatchStringPackage
= StringPackage
;
1252 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1254 // Create a blank EFI_HII_SIBT_STRING_UCS2_BLOCK to reserve new string ID.
1256 Ucs2BlockSize
= (UINT32
) sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1258 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1259 if (StringBlock
== NULL
) {
1260 Status
= EFI_OUT_OF_RESOURCES
;
1264 // Copy original string blocks, except the EFI_HII_SIBT_END.
1266 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1268 // Create a blank EFI_HII_SIBT_STRING_UCS2 block
1270 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1271 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1272 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1275 // Append a EFI_HII_SIBT_END block to the end.
1277 *BlockPtr
= EFI_HII_SIBT_END
;
1278 FreePool (StringPackage
->StringBlock
);
1279 StringPackage
->StringBlock
= StringBlock
;
1280 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1281 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1284 if (NewStringId
== 0) {
1286 // No string package is found.
1287 // Create new string package. StringId 1 is reserved for Language Name string.
1294 *StringId
= (EFI_STRING_ID
) (NewStringId
+ 1);
1297 if (MatchStringPackage
!= NULL
) {
1298 StringPackage
= MatchStringPackage
;
1301 // LanguageName is required to create a new string package.
1303 if (LanguageName
== NULL
) {
1304 Status
= EFI_INVALID_PARAMETER
;
1308 StringPackage
= AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE
));
1309 if (StringPackage
== NULL
) {
1310 Status
= EFI_OUT_OF_RESOURCES
;
1314 StringPackage
->Signature
= HII_STRING_PACKAGE_SIGNATURE
;
1315 StringPackage
->MaxStringId
= *StringId
;
1316 StringPackage
->FontId
= 0;
1317 InitializeListHead (&StringPackage
->FontInfoList
);
1320 // Fill in the string package header
1322 HeaderSize
= (UINT32
) (AsciiStrSize ((CHAR8
*) Language
) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR
));
1323 StringPackage
->StringPkgHdr
= AllocateZeroPool (HeaderSize
);
1324 if (StringPackage
->StringPkgHdr
== NULL
) {
1325 FreePool (StringPackage
);
1326 Status
= EFI_OUT_OF_RESOURCES
;
1329 StringPackage
->StringPkgHdr
->Header
.Type
= EFI_HII_PACKAGE_STRINGS
;
1330 StringPackage
->StringPkgHdr
->HdrSize
= HeaderSize
;
1331 StringPackage
->StringPkgHdr
->StringInfoOffset
= HeaderSize
;
1332 CopyMem (StringPackage
->StringPkgHdr
->LanguageWindow
, mLanguageWindow
, 16 * sizeof (CHAR16
));
1333 StringPackage
->StringPkgHdr
->LanguageName
= 1;
1334 AsciiStrCpyS (StringPackage
->StringPkgHdr
->Language
, (HeaderSize
- OFFSET_OF(EFI_HII_STRING_PACKAGE_HDR
,Language
)) / sizeof (CHAR8
), (CHAR8
*) Language
);
1337 // Calculate the length of the string blocks, including string block to record
1338 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1340 Ucs2BlockSize
= (UINT32
) (StrSize ((CHAR16
*) LanguageName
) +
1341 (*StringId
- 1) * sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
));
1343 BlockSize
= Ucs2BlockSize
+ sizeof (EFI_HII_SIBT_END_BLOCK
);
1344 StringPackage
->StringBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
1345 if (StringPackage
->StringBlock
== NULL
) {
1346 FreePool (StringPackage
->StringPkgHdr
);
1347 FreePool (StringPackage
);
1348 Status
= EFI_OUT_OF_RESOURCES
;
1353 // Insert the string block of printable language full name
1355 BlockPtr
= StringPackage
->StringBlock
;
1356 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1357 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1358 CopyMem (BlockPtr
, (EFI_STRING
) LanguageName
, StrSize ((EFI_STRING
) LanguageName
));
1359 BlockPtr
+= StrSize ((EFI_STRING
) LanguageName
);
1360 for (Index
= 2; Index
<= *StringId
- 1; Index
++) {
1361 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1362 BlockPtr
+= sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
);
1365 // Insert the end block
1367 *BlockPtr
= EFI_HII_SIBT_END
;
1370 // Append this string package node to string package array in this package list.
1372 StringPackage
->StringPkgHdr
->Header
.Length
= HeaderSize
+ BlockSize
;
1373 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
;
1374 InsertTailList (&PackageListNode
->StringPkgHdr
, &StringPackage
->StringEntry
);
1375 NewStringPackageCreated
= TRUE
;
1378 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1380 if (StringFontInfo
== NULL
) {
1382 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1384 Ucs2BlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
)
1387 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1388 if (StringBlock
== NULL
) {
1389 Status
= EFI_OUT_OF_RESOURCES
;
1393 // Copy original string blocks, except the EFI_HII_SIBT_END.
1395 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1397 // Create a EFI_HII_SIBT_STRING_UCS2 block
1399 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1400 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1401 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1402 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1403 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1406 // Append a EFI_HII_SIBT_END block to the end.
1408 *BlockPtr
= EFI_HII_SIBT_END
;
1409 FreePool (StringPackage
->StringBlock
);
1410 StringPackage
->StringBlock
= StringBlock
;
1411 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1412 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1416 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1417 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1418 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1419 // _UCS2_FONT block.
1421 Ucs2FontBlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) -
1423 if (ReferFontInfoLocally (Private
, StringPackage
, StringPackage
->FontId
, FALSE
, GlobalFont
, &LocalFont
)) {
1425 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1427 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2FontBlockSize
);
1428 if (StringBlock
== NULL
) {
1429 Status
= EFI_OUT_OF_RESOURCES
;
1433 // Copy original string blocks, except the EFI_HII_SIBT_END.
1435 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1437 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1439 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1440 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1441 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1442 *BlockPtr
= LocalFont
->FontId
;
1444 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1445 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1448 // Append a EFI_HII_SIBT_END block to the end.
1450 *BlockPtr
= EFI_HII_SIBT_END
;
1451 FreePool (StringPackage
->StringBlock
);
1452 StringPackage
->StringBlock
= StringBlock
;
1453 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2FontBlockSize
;
1454 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2FontBlockSize
;
1458 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1459 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1460 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1462 FontBlockSize
= (UINT32
) (StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
) +
1463 sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
));
1464 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ FontBlockSize
+ Ucs2FontBlockSize
);
1465 if (StringBlock
== NULL
) {
1466 Status
= EFI_OUT_OF_RESOURCES
;
1470 // Copy original string blocks, except the EFI_HII_SIBT_END.
1472 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1475 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1476 // package instance for future reference.
1478 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1480 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1481 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1482 Ext2
.Length
= (UINT16
) FontBlockSize
;
1483 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1484 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1486 *BlockPtr
= LocalFont
->FontId
;
1488 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontSize
, sizeof (UINT16
));
1489 BlockPtr
+= sizeof (UINT16
);
1490 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontStyle
, sizeof (EFI_HII_FONT_STYLE
));
1491 BlockPtr
+= sizeof (EFI_HII_FONT_STYLE
);
1494 &((EFI_FONT_INFO
*) StringFontInfo
)->FontName
,
1495 StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
)
1497 BlockPtr
+= StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
);
1499 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1501 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1502 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1503 *BlockPtr
= LocalFont
->FontId
;
1505 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1506 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1509 // Append a EFI_HII_SIBT_END block to the end.
1511 *BlockPtr
= EFI_HII_SIBT_END
;
1512 FreePool (StringPackage
->StringBlock
);
1513 StringPackage
->StringBlock
= StringBlock
;
1514 StringPackage
->StringPkgHdr
->Header
.Length
+= FontBlockSize
+ Ucs2FontBlockSize
;
1515 PackageListNode
->PackageListHdr
.PackageLength
+= FontBlockSize
+ Ucs2FontBlockSize
;
1518 // Increase the FontId to make it unique since we already add
1519 // a EFI_HII_SIBT_FONT block to this string package.
1521 StringPackage
->FontId
++;
1526 if (!EFI_ERROR (Status
) && NewStringPackageCreated
) {
1528 // Trigger any registered notification function for new string package
1530 Status
= InvokeRegisteredFunction (
1532 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
1533 (VOID
*) StringPackage
,
1534 EFI_HII_PACKAGE_STRINGS
,
1539 if (!EFI_ERROR (Status
)) {
1541 // Update MaxString Id to new StringId
1543 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1544 Link
!= &PackageListNode
->StringPkgHdr
;
1545 Link
= Link
->ForwardLink
1547 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1548 StringPackage
->MaxStringId
= *StringId
;
1550 } else if (NewStringPackageCreated
) {
1552 // Free the allocated new string Package when new string can't be added.
1554 RemoveEntryList (&StringPackage
->StringEntry
);
1555 FreePool (StringPackage
->StringBlock
);
1556 FreePool (StringPackage
->StringPkgHdr
);
1557 FreePool (StringPackage
);
1560 // The contents of HiiDataBase may updated,need to check.
1563 // Check whether need to get the contents of HiiDataBase.
1564 // Only after ReadyToBoot to do the export.
1566 if (gExportAfterReadyToBoot
) {
1567 if (!EFI_ERROR (Status
)) {
1568 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1572 EfiReleaseLock (&mHiiDatabaseLock
);
1579 This function retrieves the string specified by StringId which is associated
1580 with the specified PackageList in the language Language and copies it into
1581 the buffer specified by String.
1583 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1584 @param Language Points to the language for the retrieved string.
1585 @param PackageList The package list in the HII database to search for
1586 the specified string.
1587 @param StringId The string's id, which is unique within
1589 @param String Points to the new null-terminated string.
1590 @param StringSize On entry, points to the size of the buffer pointed
1591 to by String, in bytes. On return, points to the
1592 length of the string, in bytes.
1593 @param StringFontInfo If not NULL, points to the string's font
1594 information. It's caller's responsibility to free
1597 @retval EFI_SUCCESS The string was returned successfully.
1598 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1599 @retval EFI_NOT_FOUND The string specified by StringId is available but
1600 not in the specified language.
1601 The specified PackageList is not in the database.
1602 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but
1603 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1605 @retval EFI_INVALID_PARAMETER The Language or StringSize was NULL.
1606 @retval EFI_INVALID_PARAMETER The value referenced by StringSize was not zero and String was NULL.
1607 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1614 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1615 IN CONST CHAR8
*Language
,
1616 IN EFI_HII_HANDLE PackageList
,
1617 IN EFI_STRING_ID StringId
,
1618 OUT EFI_STRING String
,
1619 IN OUT UINTN
*StringSize
,
1620 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
1625 HII_DATABASE_PRIVATE_DATA
*Private
;
1626 HII_DATABASE_RECORD
*DatabaseRecord
;
1627 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1628 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1630 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || StringSize
== NULL
|| PackageList
== NULL
) {
1631 return EFI_INVALID_PARAMETER
;
1634 if (String
== NULL
&& *StringSize
!= 0) {
1635 return EFI_INVALID_PARAMETER
;
1638 if (!IsHiiHandleValid (PackageList
)) {
1639 return EFI_NOT_FOUND
;
1642 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1643 PackageListNode
= NULL
;
1645 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1646 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1647 if (DatabaseRecord
->Handle
== PackageList
) {
1648 PackageListNode
= DatabaseRecord
->PackageList
;
1653 if (PackageListNode
!= NULL
) {
1655 // First search: to match the StringId in the specified language.
1657 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1658 Link
!= &PackageListNode
->StringPkgHdr
;
1659 Link
= Link
->ForwardLink
1661 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1662 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1663 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1664 if (Status
!= EFI_NOT_FOUND
) {
1670 // Second search: to match the StringId in other available languages if exist.
1672 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1673 Link
!= &PackageListNode
->StringPkgHdr
;
1674 Link
= Link
->ForwardLink
1676 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1677 Status
= GetStringWorker (Private
, StringPackage
, StringId
, NULL
, NULL
, NULL
);
1678 if (!EFI_ERROR (Status
)) {
1679 return EFI_INVALID_LANGUAGE
;
1684 return EFI_NOT_FOUND
;
1690 This function updates the string specified by StringId in the specified PackageList to the text
1691 specified by String and, optionally, the font information specified by StringFontInfo.
1693 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1694 @param PackageList The package list containing the strings.
1695 @param StringId The string's id, which is unique within
1697 @param Language Points to the language for the updated string.
1698 @param String Points to the new null-terminated string.
1699 @param StringFontInfo Points to the string's font information or NULL if
1700 the string font information is not changed.
1702 @retval EFI_SUCCESS The string was updated successfully.
1703 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1705 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1706 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1708 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1715 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1716 IN EFI_HII_HANDLE PackageList
,
1717 IN EFI_STRING_ID StringId
,
1718 IN CONST CHAR8
*Language
,
1719 IN CONST EFI_STRING String
,
1720 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1725 HII_DATABASE_PRIVATE_DATA
*Private
;
1726 HII_DATABASE_RECORD
*DatabaseRecord
;
1727 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1728 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1729 UINT32 OldPackageLen
;
1731 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || String
== NULL
|| PackageList
== NULL
) {
1732 return EFI_INVALID_PARAMETER
;
1735 if (!IsHiiHandleValid (PackageList
)) {
1736 return EFI_NOT_FOUND
;
1739 EfiAcquireLock (&mHiiDatabaseLock
);
1741 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1742 PackageListNode
= NULL
;
1744 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1745 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1746 if (DatabaseRecord
->Handle
== PackageList
) {
1747 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1751 if (PackageListNode
!= NULL
) {
1752 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1753 Link
!= &PackageListNode
->StringPkgHdr
;
1754 Link
= Link
->ForwardLink
1756 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1757 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1758 OldPackageLen
= StringPackage
->StringPkgHdr
->Header
.Length
;
1759 Status
= SetStringWorker (
1763 (EFI_STRING
) String
,
1764 (EFI_FONT_INFO
*) StringFontInfo
1766 if (EFI_ERROR (Status
)) {
1767 EfiReleaseLock (&mHiiDatabaseLock
);
1770 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
- OldPackageLen
;
1772 // Check whether need to get the contents of HiiDataBase.
1773 // Only after ReadyToBoot to do the export.
1775 if (gExportAfterReadyToBoot
) {
1776 HiiGetDatabaseInfo(&Private
->HiiDatabase
);
1778 EfiReleaseLock (&mHiiDatabaseLock
);
1784 EfiReleaseLock (&mHiiDatabaseLock
);
1785 return EFI_NOT_FOUND
;
1791 This function returns the list of supported languages, in the format specified
1792 in Appendix M of UEFI 2.1 spec.
1794 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1795 @param PackageList The package list to examine.
1796 @param Languages Points to the buffer to hold the returned
1797 null-terminated ASCII string.
1798 @param LanguagesSize On entry, points to the size of the buffer pointed
1799 to by Languages, in bytes. On return, points to
1800 the length of Languages, in bytes.
1802 @retval EFI_SUCCESS The languages were returned successfully.
1803 @retval EFI_INVALID_PARAMETER The LanguagesSize was NULL.
1804 @retval EFI_INVALID_PARAMETER The value referenced by LanguagesSize is not zero and Languages is NULL.
1805 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1806 supported languages. LanguageSize is updated to
1807 contain the required size.
1808 @retval EFI_NOT_FOUND Could not find string package in specified
1815 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1816 IN EFI_HII_HANDLE PackageList
,
1817 IN OUT CHAR8
*Languages
,
1818 IN OUT UINTN
*LanguagesSize
1822 HII_DATABASE_PRIVATE_DATA
*Private
;
1823 HII_DATABASE_RECORD
*DatabaseRecord
;
1824 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1825 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1828 if (This
== NULL
|| LanguagesSize
== NULL
|| PackageList
== NULL
) {
1829 return EFI_INVALID_PARAMETER
;
1831 if (*LanguagesSize
!= 0 && Languages
== NULL
) {
1832 return EFI_INVALID_PARAMETER
;
1834 if (!IsHiiHandleValid (PackageList
)) {
1835 return EFI_NOT_FOUND
;
1838 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1840 PackageListNode
= NULL
;
1841 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1842 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1843 if (DatabaseRecord
->Handle
== PackageList
) {
1844 PackageListNode
= DatabaseRecord
->PackageList
;
1848 if (PackageListNode
== NULL
) {
1849 return EFI_NOT_FOUND
;
1853 // Search the languages in the specified packagelist.
1856 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1857 Link
!= &PackageListNode
->StringPkgHdr
;
1858 Link
= Link
->ForwardLink
1860 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1861 ResultSize
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1862 if (ResultSize
<= *LanguagesSize
) {
1863 AsciiStrCpyS (Languages
, *LanguagesSize
/ sizeof (CHAR8
), StringPackage
->StringPkgHdr
->Language
);
1864 Languages
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1865 *(Languages
- 1) = L
';';
1868 if (ResultSize
== 0) {
1869 return EFI_NOT_FOUND
;
1872 if (*LanguagesSize
< ResultSize
) {
1873 *LanguagesSize
= ResultSize
;
1874 return EFI_BUFFER_TOO_SMALL
;
1877 *(Languages
- 1) = 0;
1883 Each string package has associated with it a single primary language and zero
1884 or more secondary languages. This routine returns the secondary languages
1885 associated with a package list.
1887 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1888 @param PackageList The package list to examine.
1889 @param PrimaryLanguage Points to the null-terminated ASCII string that specifies
1890 the primary language. Languages are specified in the
1891 format specified in Appendix M of the UEFI 2.0 specification.
1892 @param SecondaryLanguages Points to the buffer to hold the returned null-terminated
1893 ASCII string that describes the list of
1894 secondary languages for the specified
1895 PrimaryLanguage. If there are no secondary
1896 languages, the function returns successfully, but
1897 this is set to NULL.
1898 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed
1899 to by SecondaryLanguages, in bytes. On return,
1900 points to the length of SecondaryLanguages in bytes.
1902 @retval EFI_SUCCESS Secondary languages were correctly returned.
1903 @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguagesSize was NULL.
1904 @retval EFI_INVALID_PARAMETER The value referenced by SecondaryLanguagesSize is not
1905 zero and SecondaryLanguages is NULL.
1906 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is
1907 too small to hold the returned information.
1908 SecondaryLanguageSize is updated to hold the size of
1909 the buffer required.
1910 @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not
1911 present in the specified package list.
1912 @retval EFI_NOT_FOUND The specified PackageList is not in the Database.
1917 HiiGetSecondaryLanguages (
1918 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1919 IN EFI_HII_HANDLE PackageList
,
1920 IN CONST CHAR8
*PrimaryLanguage
,
1921 IN OUT CHAR8
*SecondaryLanguages
,
1922 IN OUT UINTN
*SecondaryLanguagesSize
1927 HII_DATABASE_PRIVATE_DATA
*Private
;
1928 HII_DATABASE_RECORD
*DatabaseRecord
;
1929 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1930 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1934 if (This
== NULL
|| PackageList
== NULL
|| PrimaryLanguage
== NULL
|| SecondaryLanguagesSize
== NULL
) {
1935 return EFI_INVALID_PARAMETER
;
1937 if (SecondaryLanguages
== NULL
&& *SecondaryLanguagesSize
!= 0) {
1938 return EFI_INVALID_PARAMETER
;
1940 if (!IsHiiHandleValid (PackageList
)) {
1941 return EFI_NOT_FOUND
;
1944 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1946 PackageListNode
= NULL
;
1947 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1948 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1949 if (DatabaseRecord
->Handle
== PackageList
) {
1950 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1954 if (PackageListNode
== NULL
) {
1955 return EFI_NOT_FOUND
;
1960 for (Link1
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1961 Link1
!= &PackageListNode
->StringPkgHdr
;
1962 Link1
= Link1
->ForwardLink
1964 StringPackage
= CR (Link1
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1965 if (HiiCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) PrimaryLanguage
)) {
1966 Languages
= StringPackage
->StringPkgHdr
->Language
;
1968 // Language is a series of ';' terminated strings, first one is primary
1969 // language and following with other secondary languages or NULL if no
1970 // secondary languages any more.
1972 Languages
= AsciiStrStr (Languages
, ";");
1973 if (Languages
== NULL
) {
1978 ResultSize
= AsciiStrSize (Languages
);
1979 if (ResultSize
<= *SecondaryLanguagesSize
) {
1980 AsciiStrCpyS (SecondaryLanguages
, *SecondaryLanguagesSize
/ sizeof (CHAR8
), Languages
);
1982 *SecondaryLanguagesSize
= ResultSize
;
1983 return EFI_BUFFER_TOO_SMALL
;
1990 return EFI_INVALID_LANGUAGE
;
1994 Converts the ascii character of the string from uppercase to lowercase.
1995 This is a internal function.
1997 @param ConfigString String to be converted
2003 IN CHAR8
*ConfigString
2006 ASSERT (ConfigString
!= NULL
);
2009 // Convert all hex digits in range [A-F] in the configuration header to [a-f]
2011 for (; *ConfigString
!= '\0'; ConfigString
++) {
2012 if ( *ConfigString
>= 'A' && *ConfigString
<= 'Z') {
2013 *ConfigString
= (CHAR8
) (*ConfigString
- 'A' + 'a');
2019 Compare whether two names of languages are identical.
2021 @param Language1 Name of language 1 from StringPackage
2022 @param Language2 Name of language 2 to be compared with language 1.
2025 @retval FALSE not same
2029 HiiCompareLanguage (
2030 IN CHAR8
*Language1
,
2040 // Convert to lower to compare.
2042 StrLen
= AsciiStrSize (Language1
);
2043 Lan1
= AllocateZeroPool (StrLen
);
2044 ASSERT (Lan1
!= NULL
);
2045 AsciiStrCpyS(Lan1
, StrLen
/ sizeof (CHAR8
), Language1
);
2046 AsciiHiiToLower (Lan1
);
2048 StrLen
= AsciiStrSize (Language2
);
2049 Lan2
= AllocateZeroPool (StrLen
);
2050 ASSERT (Lan2
!= NULL
);
2051 AsciiStrCpyS(Lan2
, StrLen
/ sizeof (CHAR8
), Language2
);
2052 AsciiHiiToLower (Lan2
);
2055 // Compare the Primary Language in Language1 to Language2
2057 for (Index
= 0; Lan1
[Index
] != 0 && Lan1
[Index
] != ';'; Index
++) {
2058 if (Lan1
[Index
] != Lan2
[Index
]) {
2060 // Return FALSE if any characters are different.
2072 // Only return TRUE if Language2[Index] is a Null-terminator which means
2073 // the Primary Language in Language1 is the same length as Language2. If
2074 // Language2[Index] is not a Null-terminator, then Language2 is longer than
2075 // the Primary Language in Language1, and FALSE must be returned.
2077 return (BOOLEAN
) (Language2
[Index
] == 0);