3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Implementation for EFI_HII_STRING_PROTOCOL.
26 #include "HiiDatabase.h"
28 CHAR16 mLanguageWindow
[16] = {
29 0x0000, 0x0080, 0x0100, 0x0300,
30 0x2000, 0x2080, 0x2100, 0x3000,
31 0x0080, 0x00C0, 0x0400, 0x0600,
32 0x0900, 0x3040, 0x30A0, 0xFF00
37 This function checks whether a global font info is referred by local
38 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
39 a HII_FONT_INFO to refer it locally.
41 @param Private Hii database private structure.
42 @param StringPackage HII string package instance.
43 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
44 the same EFI_FONT_INFO is permitted. Otherwise it
46 @param GlobalFontInfo Input a global font info which specify a
48 @param LocalFontInfo Output a local font info which refers to a
51 @retval TRUE Already referred before calling this function.
52 @retval FALSE Not referred before calling this function.
57 ReferFontInfoLocally (
58 IN HII_DATABASE_PRIVATE_DATA
*Private
,
59 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
60 IN BOOLEAN DuplicateEnable
,
61 IN HII_GLOBAL_FONT_INFO
*GlobalFontInfo
,
62 OUT HII_FONT_INFO
**LocalFontInfo
65 HII_FONT_INFO
*LocalFont
;
68 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& GlobalFontInfo
!= NULL
&& LocalFontInfo
!= NULL
);
70 if (!DuplicateEnable
) {
71 for (Link
= StringPackage
->FontInfoList
.ForwardLink
;
72 Link
!= &StringPackage
->FontInfoList
;
73 Link
= Link
->ForwardLink
75 LocalFont
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
76 if (LocalFont
->GlobalEntry
== &GlobalFontInfo
->Entry
) {
78 // Already referred by local font info list, return directly.
80 *LocalFontInfo
= LocalFont
;
86 // Since string package tool set FontId initially to 0 and increases it
87 // progressively by one, StringPackage->FondId always represents an unique
88 // and available FontId.
90 // FontId identifies EFI_FONT_INFO in local string package uniquely.
91 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
92 // EFI_FONT_INFO uniquely in whole hii database.
94 LocalFont
= (HII_FONT_INFO
*) AllocateZeroPool (sizeof (HII_FONT_INFO
));
95 ASSERT (LocalFont
!= NULL
);
97 LocalFont
->Signature
= HII_FONT_INFO_SIGNATURE
;
98 LocalFont
->FontId
= StringPackage
->FontId
;
99 LocalFont
->GlobalEntry
= &GlobalFontInfo
->Entry
;
100 InsertTailList (&StringPackage
->FontInfoList
, &LocalFont
->Entry
);
102 StringPackage
->FontId
++;
104 *LocalFontInfo
= LocalFont
;
110 Convert Ascii string text to unicode string test.
112 @param StringSrc Points to current null-terminated Ascii string.
113 @param StringDest Buffer to store the converted string text.
114 @param BufferSize Length of the buffer.
116 @retval EFI_SUCCESS The string text was outputed successfully.
117 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
118 text. BufferSize is updated to the required buffer
124 ConvertToUnicodeText (
125 OUT EFI_STRING StringDest
,
127 IN OUT UINTN
*BufferSize
133 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
135 StringSize
= AsciiStrSize (StringSrc
) * 2;
136 if (*BufferSize
< StringSize
) {
137 *BufferSize
= StringSize
;
138 return EFI_BUFFER_TOO_SMALL
;
141 for (Index
= 0; Index
< AsciiStrLen (StringSrc
); Index
++) {
142 StringDest
[Index
] = (CHAR16
) StringSrc
[Index
];
145 StringDest
[Index
] = 0;
151 Calculate the size of StringSrc and output it. If StringDest is not NULL,
152 copy string text from src to dest.
154 @param StringSrc Points to current null-terminated string.
155 @param StringDest Buffer to store the string text.
156 @param BufferSize Length of the buffer.
158 @retval EFI_SUCCESS The string text was outputed successfully.
159 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
160 text. BufferSize is updated to the required buffer
166 GetUnicodeStringTextOrSize (
167 OUT EFI_STRING StringDest
, OPTIONAL
169 IN OUT UINTN
*BufferSize
176 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
178 ZeroMem (&Zero
, sizeof (CHAR16
));
179 StringSize
= sizeof (CHAR16
);
180 StringPtr
= StringSrc
;
181 while (CompareMem (StringPtr
, &Zero
, sizeof (CHAR16
)) != 0) {
182 StringSize
+= sizeof (CHAR16
);
183 StringPtr
+= sizeof (CHAR16
);
186 if (StringDest
!= NULL
) {
187 if (*BufferSize
< StringSize
) {
188 *BufferSize
= StringSize
;
189 return EFI_BUFFER_TOO_SMALL
;
191 CopyMem (StringDest
, StringSrc
, StringSize
);
195 *BufferSize
= StringSize
;
201 Copy string font info to a buffer.
203 @param StringPackage Hii string package instance.
204 @param FontId Font identifier which is unique in a string
206 @param StringFontInfo Buffer to record the output font info. It's
207 caller's responsibility to free this buffer.
209 @retval EFI_SUCCESS The string font is outputed successfully.
210 @retval EFI_NOT_FOUND The specified font id does not exist.
216 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
218 OUT EFI_FONT_INFO
**StringFontInfo
222 HII_FONT_INFO
*FontInfo
;
223 HII_GLOBAL_FONT_INFO
*GlobalFont
;
225 ASSERT (StringFontInfo
!= NULL
&& StringPackage
!= NULL
);
227 for (Link
= StringPackage
->FontInfoList
.ForwardLink
; Link
!= &StringPackage
->FontInfoList
; Link
= Link
->ForwardLink
) {
228 FontInfo
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
229 if (FontInfo
->FontId
== FontId
) {
230 GlobalFont
= CR (FontInfo
->GlobalEntry
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
231 *StringFontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (GlobalFont
->FontInfoSize
);
232 if (*StringFontInfo
== NULL
) {
233 return EFI_OUT_OF_RESOURCES
;
235 CopyMem (*StringFontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
240 return EFI_NOT_FOUND
;
245 Parse all string blocks to find a String block specified by StringId.
246 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
247 within this string package and backup its information.
248 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_END).
250 @param Private Hii database private structure.
251 @param StringPackage Hii string package instance.
252 @param StringId The string's id, which is unique within
254 @param BlockType Output the block type of found string block.
255 @param StringBlockAddr Output the block address of found string block.
256 @param StringTextOffset Offset, relative to the found block address, of
257 the string text information.
258 @param LastStringId Output the last string id when StringId = 0.
260 @retval EFI_SUCCESS The string text and font is retrieved
262 @retval EFI_NOT_FOUND The specified text or font info can not be found
264 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
270 IN HII_DATABASE_PRIVATE_DATA
*Private
,
271 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
272 IN EFI_STRING_ID StringId
,
273 OUT UINT8
*BlockType
, OPTIONAL
274 OUT UINT8
**StringBlockAddr
, OPTIONAL
275 OUT UINTN
*StringTextOffset
, OPTIONAL
276 OUT EFI_STRING_ID
*LastStringId OPTIONAL
280 EFI_STRING_ID CurrentStringId
;
283 UINT8
*StringTextPtr
;
285 HII_FONT_INFO
*LocalFont
;
286 EFI_FONT_INFO
*FontInfo
;
287 HII_GLOBAL_FONT_INFO
*GlobalFont
;
291 EFI_HII_FONT_STYLE FontStyle
;
294 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
299 ASSERT (StringPackage
!= NULL
);
300 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
304 if (StringId
!= (EFI_STRING_ID
) (-1) && StringId
!= 0) {
305 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
307 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
310 ZeroMem (&Zero
, sizeof (CHAR16
));
313 // Parse the string blocks to get the string text and font.
315 BlockHdr
= StringPackage
->StringBlock
;
318 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
320 case EFI_HII_SIBT_STRING_SCSU
:
321 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
322 StringTextPtr
= BlockHdr
+ Offset
;
323 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
327 case EFI_HII_SIBT_STRING_SCSU_FONT
:
328 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
329 StringTextPtr
= BlockHdr
+ Offset
;
330 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
334 case EFI_HII_SIBT_STRINGS_SCSU
:
335 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
336 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
);
337 BlockSize
+= StringTextPtr
- BlockHdr
;
339 for (Index
= 0; Index
< StringCount
; Index
++) {
340 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
341 if (CurrentStringId
== StringId
) {
342 *BlockType
= *BlockHdr
;
343 *StringBlockAddr
= BlockHdr
;
344 *StringTextOffset
= StringTextPtr
- BlockHdr
;
347 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
352 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
355 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
358 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
359 BlockSize
+= StringTextPtr
- BlockHdr
;
361 for (Index
= 0; Index
< StringCount
; Index
++) {
362 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
363 if (CurrentStringId
== StringId
) {
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 *BlockType
= *BlockHdr
;
408 *StringBlockAddr
= BlockHdr
;
409 *StringTextOffset
= StringTextPtr
- BlockHdr
;
412 StringTextPtr
= StringTextPtr
+ StringSize
;
417 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
418 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
419 StringTextPtr
= BlockHdr
+ Offset
;
423 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
426 for (Index
= 0; Index
< StringCount
; Index
++) {
427 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
428 BlockSize
+= StringSize
;
429 if (CurrentStringId
== StringId
) {
430 *BlockType
= *BlockHdr
;
431 *StringBlockAddr
= BlockHdr
;
432 *StringTextOffset
= StringTextPtr
- BlockHdr
;
435 StringTextPtr
= StringTextPtr
+ StringSize
;
440 case EFI_HII_SIBT_DUPLICATE
:
441 if (CurrentStringId
== StringId
) {
443 // Incoming StringId is an id of a duplicate string block.
444 // Update the StringId to be the previous string block.
445 // Go back to the header of string block to search.
449 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
),
450 sizeof (EFI_STRING_ID
)
452 ASSERT (StringId
!= CurrentStringId
);
456 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
461 case EFI_HII_SIBT_SKIP1
:
462 SkipCount
= (UINT16
) (*(BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
463 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
464 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
467 case EFI_HII_SIBT_SKIP2
:
468 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
469 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
470 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
473 case EFI_HII_SIBT_EXT1
:
476 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
479 BlockSize
+= Length8
;
482 case EFI_HII_SIBT_EXT2
:
483 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
484 if (Ext2
.BlockType2
== EFI_HII_SIBT_FONT
&& StringId
== (EFI_STRING_ID
) (-1)) {
486 // Find the relationship between global font info and the font info of
487 // this EFI_HII_SIBT_FONT block then backup its information in local package.
489 BlockHdr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
) + sizeof (UINT8
);
490 CopyMem (&FontSize
, BlockHdr
, sizeof (UINT16
));
491 BlockHdr
+= sizeof (UINT16
);
492 CopyMem (&FontStyle
, BlockHdr
, sizeof (EFI_HII_FONT_STYLE
));
493 BlockHdr
+= sizeof (EFI_HII_FONT_STYLE
);
494 GetUnicodeStringTextOrSize (NULL
, BlockHdr
, &StringSize
);
496 FontInfoSize
= sizeof (EFI_FONT_INFO
) - sizeof (CHAR16
) + StringSize
;
497 FontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (FontInfoSize
);
498 if (FontInfo
== NULL
) {
499 return EFI_OUT_OF_RESOURCES
;
501 FontInfo
->FontStyle
= FontStyle
;
502 FontInfo
->FontSize
= FontSize
;
503 CopyMem (FontInfo
->FontName
, BlockHdr
, StringSize
);
505 if (IsFontInfoExisted (Private
, FontInfo
, NULL
, NULL
, &GlobalFont
)) {
507 // If find the corresponding global font info, save the relationship.
509 ReferFontInfoLocally (Private
, StringPackage
, TRUE
, GlobalFont
, &LocalFont
);
513 // If can not find, ignore this EFI_HII_SIBT_FONT block.
515 SafeFreePool (FontInfo
);
518 BlockSize
+= Ext2
.Length
;
522 case EFI_HII_SIBT_EXT4
:
525 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
529 BlockSize
+= Length32
;
537 if (StringId
== CurrentStringId
- 1) {
538 *BlockType
= *BlockHdr
;
539 *StringBlockAddr
= BlockHdr
;
540 *StringTextOffset
= Offset
;
544 if (StringId
< CurrentStringId
- 1) {
545 return EFI_NOT_FOUND
;
548 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
552 if (StringId
== (EFI_STRING_ID
) (-1)) {
556 if (StringId
== 0 && LastStringId
!= NULL
) {
557 *LastStringId
= CurrentStringId
;
561 return EFI_NOT_FOUND
;
566 Parse all string blocks to get a string specified by StringId.
568 @param Private Hii database private structure.
569 @param StringPackage Hii string package instance.
570 @param StringId The string's id, which is unique within
572 @param String Points to retrieved null-terminated string.
573 @param StringSize On entry, points to the size of the buffer pointed
574 to by String, in bytes. On return, points to the
575 length of the string, in bytes.
576 @param StringFontInfo If not NULL, allocate a buffer to record the
577 output font info. It's caller's responsibility to
580 @retval EFI_SUCCESS The string text and font is retrieved
582 @retval EFI_NOT_FOUND The specified text or font info can not be found
584 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
591 IN HII_DATABASE_PRIVATE_DATA
*Private
,
592 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
593 IN EFI_STRING_ID StringId
,
594 OUT EFI_STRING String
,
595 IN OUT UINTN
*StringSize
,
596 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
599 UINT8
*StringTextPtr
;
601 UINT8
*StringBlockAddr
;
602 UINTN StringTextOffset
;
606 ASSERT (StringPackage
!= NULL
&& StringSize
!= NULL
);
607 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
610 // Find the specified string block
612 Status
= FindStringBlock (
621 if (EFI_ERROR (Status
)) {
626 // Get the string text.
628 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
630 case EFI_HII_SIBT_STRING_SCSU
:
631 case EFI_HII_SIBT_STRING_SCSU_FONT
:
632 case EFI_HII_SIBT_STRINGS_SCSU
:
633 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
634 Status
= ConvertToUnicodeText (String
, (CHAR8
*) StringTextPtr
, StringSize
);
636 case EFI_HII_SIBT_STRING_UCS2
:
637 case EFI_HII_SIBT_STRING_UCS2_FONT
:
638 case EFI_HII_SIBT_STRINGS_UCS2
:
639 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
640 Status
= GetUnicodeStringTextOrSize (String
, StringTextPtr
, StringSize
);
643 return EFI_NOT_FOUND
;
645 if (EFI_ERROR (Status
)) {
650 // Get the string font.
652 if (StringFontInfo
!= NULL
) {
654 case EFI_HII_SIBT_STRING_SCSU_FONT
:
655 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
656 case EFI_HII_SIBT_STRING_UCS2_FONT
:
657 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
658 FontId
= *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
659 return GetStringFontInfo (StringPackage
, FontId
, StringFontInfo
);
671 Parse all string blocks to set a String specified by StringId.
673 @param Private HII database driver private structure.
674 @param StringPackage HII string package instance.
675 @param StringId The string's id, which is unique within
677 @param String Points to the new null-terminated string.
678 @param StringFontInfo Points to the input font info.
680 @retval EFI_SUCCESS The string was updated successfully.
681 @retval EFI_NOT_FOUND The string specified by StringId is not in the
683 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
684 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
686 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
693 IN HII_DATABASE_PRIVATE_DATA
*Private
,
694 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
695 IN EFI_STRING_ID StringId
,
696 IN EFI_STRING String
,
697 IN EFI_FONT_INFO
*StringFontInfo OPTIONAL
700 UINT8
*StringTextPtr
;
702 UINT8
*StringBlockAddr
;
703 UINTN StringTextOffset
;
709 HII_FONT_INFO
*LocalFont
;
710 HII_GLOBAL_FONT_INFO
*GlobalFont
;
712 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
717 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& String
!= NULL
);
718 ASSERT (Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
720 // Find the specified string block
722 Status
= FindStringBlock (
731 if (EFI_ERROR (Status
)) {
740 // Set the string font according to input font information.
742 if (StringFontInfo
!= NULL
) {
744 // The input StringFontInfo should exist in current database
746 if (!IsFontInfoExisted (Private
, StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
747 return EFI_INVALID_PARAMETER
;
749 Referred
= ReferFontInfoLocally (Private
, StringPackage
, FALSE
, GlobalFont
, &LocalFont
);
753 // Update the FontId of the specified string block
756 case EFI_HII_SIBT_STRING_SCSU_FONT
:
757 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
758 case EFI_HII_SIBT_STRING_UCS2_FONT
:
759 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
760 *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
)) = LocalFont
->FontId
;
763 return EFI_NOT_FOUND
;
768 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
771 // Set the string text.
773 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
775 case EFI_HII_SIBT_STRING_SCSU
:
776 case EFI_HII_SIBT_STRING_SCSU_FONT
:
777 case EFI_HII_SIBT_STRINGS_SCSU
:
778 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
779 BlockSize
= OldBlockSize
+ StrLen (String
);
780 BlockSize
-= AsciiStrLen ((CHAR8
*) StringTextPtr
);
781 Block
= AllocateZeroPool (BlockSize
);
783 return EFI_OUT_OF_RESOURCES
;
786 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
787 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
789 while (*String
!= 0) {
790 *BlockPtr
++ = (CHAR8
) *String
++;
795 TmpSize
= OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - AsciiStrSize ((CHAR8
*) StringTextPtr
);
798 StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
),
802 SafeFreePool (StringPackage
->StringBlock
);
803 StringPackage
->StringBlock
= Block
;
804 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
807 case EFI_HII_SIBT_STRING_UCS2
:
808 case EFI_HII_SIBT_STRING_UCS2_FONT
:
809 case EFI_HII_SIBT_STRINGS_UCS2
:
810 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
812 // Use StrSize to store the size of the specified string, including the NULL
815 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
817 BlockSize
= OldBlockSize
+ StrSize (String
) - StringSize
;
818 Block
= AllocateZeroPool (BlockSize
);
820 return EFI_OUT_OF_RESOURCES
;
823 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
824 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
826 CopyMem (BlockPtr
, String
, StrSize (String
));
827 BlockPtr
+= StrSize (String
);
831 StringTextPtr
+ StringSize
,
832 OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - StringSize
835 SafeFreePool (StringPackage
->StringBlock
);
836 StringPackage
->StringBlock
= Block
;
837 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
841 return EFI_NOT_FOUND
;
845 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
846 // StringFontInfo does not exist in current string package.
848 // This new block does not impact on the value of StringId.
851 if (StringFontInfo
== NULL
|| Referred
) {
855 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
856 BlockSize
= OldBlockSize
+ sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
) +
857 StrSize (GlobalFont
->FontInfo
->FontName
);
859 Block
= AllocateZeroPool (BlockSize
);
861 return EFI_OUT_OF_RESOURCES
;
865 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
866 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
867 Ext2
.Length
= (UINT16
) (BlockSize
- OldBlockSize
);
868 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
869 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
871 *BlockPtr
= LocalFont
->FontId
;
872 BlockPtr
+= sizeof (UINT8
);
873 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontSize
, sizeof (UINT16
));
874 BlockPtr
+= sizeof (UINT16
);
875 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontStyle
, sizeof (UINT32
));
876 BlockPtr
+= sizeof (UINT32
);
879 GlobalFont
->FontInfo
->FontName
,
880 StrSize (GlobalFont
->FontInfo
->FontName
)
882 BlockPtr
+= StrSize (GlobalFont
->FontInfo
->FontName
);
884 CopyMem (BlockPtr
, StringPackage
->StringBlock
, OldBlockSize
);
886 SafeFreePool (StringPackage
->StringBlock
);
887 StringPackage
->StringBlock
= Block
;
888 StringPackage
->StringPkgHdr
->Header
.Length
+= Ext2
.Length
;
896 This function adds the string String to the group of strings owned by PackageList, with the
897 specified font information StringFontInfo and returns a new string id.
899 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
900 @param PackageList Handle of the package list where this string will
902 @param StringId On return, contains the new strings id, which is
903 unique within PackageList.
904 @param Language Points to the language for the new string.
905 @param LanguageName Points to the printable language name to associate
906 with the passed in Language field.If LanguageName
907 is not NULL and the string package header's
908 LanguageName associated with a given Language is
909 not zero, the LanguageName being passed in will
911 @param String Points to the new null-terminated string.
912 @param StringFontInfo Points to the new string's font information or
913 NULL if the string should have the default system
914 font, size and style.
916 @retval EFI_SUCCESS The new string was added successfully.
917 @retval EFI_NOT_FOUND The specified PackageList could not be found in
919 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
920 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
922 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
929 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
930 IN EFI_HII_HANDLE PackageList
,
931 OUT EFI_STRING_ID
*StringId
,
932 IN CONST CHAR8
*Language
,
933 IN CONST CHAR16
*LanguageName
, OPTIONAL
934 IN CONST EFI_STRING String
,
935 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
941 HII_DATABASE_PRIVATE_DATA
*Private
;
942 HII_DATABASE_RECORD
*DatabaseRecord
;
943 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
944 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
950 UINT32 Ucs2BlockSize
;
951 UINT32 FontBlockSize
;
952 UINT32 Ucs2FontBlockSize
;
953 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
954 HII_FONT_INFO
*LocalFont
;
955 HII_GLOBAL_FONT_INFO
*GlobalFont
;
957 if (This
== NULL
|| String
== NULL
|| StringId
== NULL
|| Language
== NULL
|| PackageList
== NULL
) {
958 return EFI_INVALID_PARAMETER
;
961 if (!IsHiiHandleValid (PackageList
)) {
962 return EFI_NOT_FOUND
;
965 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
969 // If StringFontInfo specify a paritcular font, it should exist in current database.
971 if (StringFontInfo
!= NULL
) {
972 if (!IsFontInfoExisted (Private
, (EFI_FONT_INFO
*) StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
973 return EFI_INVALID_PARAMETER
;
978 // Get the matching package list.
980 PackageListNode
= NULL
;
981 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
982 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
983 if (DatabaseRecord
->Handle
== PackageList
) {
984 PackageListNode
= DatabaseRecord
->PackageList
;
988 if (PackageListNode
== NULL
) {
989 return EFI_NOT_FOUND
;
993 // Try to get the matching string package. Create a new string package when failed.
995 StringPackage
= NULL
;
997 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
998 Link
!= &PackageListNode
->StringPkgHdr
;
999 Link
= Link
->ForwardLink
1001 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1002 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1010 // LanguageName is required to create a new string package.
1012 if (LanguageName
== NULL
) {
1013 return EFI_INVALID_PARAMETER
;
1016 StringPackage
= AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE
));
1017 if (StringPackage
== NULL
) {
1018 return EFI_OUT_OF_RESOURCES
;
1021 StringPackage
->Signature
= HII_STRING_PACKAGE_SIGNATURE
;
1022 StringPackage
->FontId
= 0;
1023 InitializeListHead (&StringPackage
->FontInfoList
);
1026 // Fill in the string package header
1028 HeaderSize
= (UINT32
) (AsciiStrSize ((CHAR8
*) Language
) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR
));
1029 StringPackage
->StringPkgHdr
= AllocateZeroPool (HeaderSize
);
1030 if (StringPackage
->StringPkgHdr
== NULL
) {
1031 SafeFreePool (StringPackage
);
1032 return EFI_OUT_OF_RESOURCES
;
1034 StringPackage
->StringPkgHdr
->Header
.Type
= EFI_HII_PACKAGE_STRINGS
;
1035 StringPackage
->StringPkgHdr
->HdrSize
= HeaderSize
;
1036 StringPackage
->StringPkgHdr
->StringInfoOffset
= HeaderSize
;
1037 CopyMem (StringPackage
->StringPkgHdr
->LanguageWindow
, mLanguageWindow
, 16 * sizeof (CHAR16
));;
1038 StringPackage
->StringPkgHdr
->LanguageName
= 1;
1039 AsciiStrCpy (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
);
1042 // Calculate the length of the string blocks, including string block to record
1043 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1045 Ucs2BlockSize
= (UINT32
) (StrSize ((CHAR16
*) LanguageName
) +
1046 sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
));
1048 BlockSize
= Ucs2BlockSize
+ sizeof (EFI_HII_SIBT_END_BLOCK
);
1049 StringPackage
->StringBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
1050 if (StringPackage
->StringBlock
== NULL
) {
1051 SafeFreePool (StringPackage
->StringPkgHdr
);
1052 SafeFreePool (StringPackage
);
1053 return EFI_OUT_OF_RESOURCES
;
1057 // Insert the string block of printable language full name
1059 BlockPtr
= StringPackage
->StringBlock
;
1060 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1061 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1062 CopyMem (BlockPtr
, (EFI_STRING
) LanguageName
, StrSize ((EFI_STRING
) LanguageName
));
1063 BlockPtr
+= StrSize ((EFI_STRING
) LanguageName
);
1066 // Insert the end block
1068 *BlockPtr
= EFI_HII_SIBT_END
;
1071 // Append this string package node to string package array in this package list.
1073 StringPackage
->StringPkgHdr
->Header
.Length
= HeaderSize
+ BlockSize
;
1074 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
;
1075 InsertTailList (&PackageListNode
->StringPkgHdr
, &StringPackage
->StringEntry
);
1080 // Create a string block and corresponding font block if exists, then append them
1081 // to the end of the string package.
1083 Status
= FindStringBlock (
1092 if (EFI_ERROR (Status
)) {
1096 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1098 if (StringFontInfo
== NULL
) {
1100 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1103 Ucs2BlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
)
1106 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1107 if (StringBlock
== NULL
) {
1108 return EFI_OUT_OF_RESOURCES
;
1111 // Copy original string blocks, except the EFI_HII_SIBT_END.
1113 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1115 // Create a EFI_HII_SIBT_STRING_UCS2 block
1117 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1118 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1119 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1120 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1121 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1124 // Append a EFI_HII_SIBT_END block to the end.
1126 *BlockPtr
= EFI_HII_SIBT_END
;
1127 SafeFreePool (StringPackage
->StringBlock
);
1128 StringPackage
->StringBlock
= StringBlock
;
1129 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1130 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1134 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1135 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1136 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1137 // _UCS2_FONT block.
1139 Ucs2FontBlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) -
1141 if (ReferFontInfoLocally (Private
, StringPackage
, FALSE
, GlobalFont
, &LocalFont
)) {
1143 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1145 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2FontBlockSize
);
1146 if (StringBlock
== NULL
) {
1147 return EFI_OUT_OF_RESOURCES
;
1150 // Copy original string blocks, except the EFI_HII_SIBT_END.
1152 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1154 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1156 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1157 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1158 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1159 *BlockPtr
= LocalFont
->FontId
;
1160 BlockPtr
+= sizeof (UINT8
);
1161 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1162 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1165 // Append a EFI_HII_SIBT_END block to the end.
1167 *BlockPtr
= EFI_HII_SIBT_END
;
1168 SafeFreePool (StringPackage
->StringBlock
);
1169 StringPackage
->StringBlock
= StringBlock
;
1170 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2FontBlockSize
;
1171 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2FontBlockSize
;
1175 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1176 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1177 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1179 FontBlockSize
= (UINT32
) (StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
) +
1180 sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
));
1181 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ FontBlockSize
+ Ucs2FontBlockSize
);
1182 if (StringBlock
== NULL
) {
1183 return EFI_OUT_OF_RESOURCES
;
1186 // Copy original string blocks, except the EFI_HII_SIBT_END.
1188 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1191 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1192 // package instance for future reference.
1194 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1196 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1197 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1198 Ext2
.Length
= (UINT16
) FontBlockSize
;
1199 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1200 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1202 *BlockPtr
= LocalFont
->FontId
;
1203 BlockPtr
+= sizeof (UINT8
);
1204 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontSize
, sizeof (UINT16
));
1205 BlockPtr
+= sizeof (UINT16
);
1206 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontStyle
, sizeof (EFI_HII_FONT_STYLE
));
1207 BlockPtr
+= sizeof (EFI_HII_FONT_STYLE
);
1210 &((EFI_FONT_INFO
*) StringFontInfo
)->FontName
,
1211 StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
)
1215 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1217 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1218 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1219 *BlockPtr
= LocalFont
->FontId
;
1220 BlockPtr
+= sizeof (UINT8
);
1221 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1222 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1225 // Append a EFI_HII_SIBT_END block to the end.
1227 *BlockPtr
= EFI_HII_SIBT_END
;
1228 SafeFreePool (StringPackage
->StringBlock
);
1229 StringPackage
->StringBlock
= StringBlock
;
1230 StringPackage
->StringPkgHdr
->Header
.Length
+= FontBlockSize
+ Ucs2FontBlockSize
;
1231 PackageListNode
->PackageListHdr
.PackageLength
+= FontBlockSize
+ Ucs2FontBlockSize
;
1240 This function retrieves the string specified by StringId which is associated
1241 with the specified PackageList in the language Language and copies it into
1242 the buffer specified by String.
1244 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1245 @param Language Points to the language for the retrieved string.
1246 @param PackageList The package list in the HII database to search for
1247 the specified string.
1248 @param StringId The string's id, which is unique within
1250 @param String Points to the new null-terminated string.
1251 @param StringSize On entry, points to the size of the buffer pointed
1252 to by String, in bytes. On return, points to the
1253 length of the string, in bytes.
1254 @param StringFontInfo If not NULL, points to the string's font
1255 information. It's caller's responsibility to free
1258 @retval EFI_SUCCESS The string was returned successfully.
1259 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1260 @retval EFI_NOT_FOUND The string specified by StringId is available but
1261 not in the specified language.
1262 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1264 @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.
1265 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1272 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1273 IN CONST CHAR8
*Language
,
1274 IN EFI_HII_HANDLE PackageList
,
1275 IN EFI_STRING_ID StringId
,
1276 OUT EFI_STRING String
,
1277 IN OUT UINTN
*StringSize
,
1278 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
1283 HII_DATABASE_PRIVATE_DATA
*Private
;
1284 HII_DATABASE_RECORD
*DatabaseRecord
;
1285 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1286 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1288 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || StringSize
== NULL
|| PackageList
== NULL
) {
1289 return EFI_INVALID_PARAMETER
;
1292 if (String
== NULL
&& *StringSize
!= 0) {
1293 return EFI_INVALID_PARAMETER
;
1296 if (!IsHiiHandleValid (PackageList
)) {
1297 return EFI_NOT_FOUND
;
1300 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1301 PackageListNode
= NULL
;
1303 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1304 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1305 if (DatabaseRecord
->Handle
== PackageList
) {
1306 PackageListNode
= DatabaseRecord
->PackageList
;
1311 if (PackageListNode
!= NULL
) {
1312 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1313 Link
!= &PackageListNode
->StringPkgHdr
;
1314 Link
= Link
->ForwardLink
1316 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1317 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1318 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1319 if (Status
!= EFI_NOT_FOUND
) {
1326 return EFI_NOT_FOUND
;
1332 This function updates the string specified by StringId in the specified PackageList to the text
1333 specified by String and, optionally, the font information specified by StringFontInfo.
1335 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1336 @param PackageList The package list containing the strings.
1337 @param StringId The string's id, which is unique within
1339 @param Language Points to the language for the updated string.
1340 @param String Points to the new null-terminated string.
1341 @param StringFontInfo Points to the string's font information or NULL if
1342 the string font information is not changed.
1344 @retval EFI_SUCCESS The string was updated successfully.
1345 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1347 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1348 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1350 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1357 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1358 IN EFI_HII_HANDLE PackageList
,
1359 IN EFI_STRING_ID StringId
,
1360 IN CONST CHAR8
*Language
,
1361 IN CONST EFI_STRING String
,
1362 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1367 HII_DATABASE_PRIVATE_DATA
*Private
;
1368 HII_DATABASE_RECORD
*DatabaseRecord
;
1369 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1370 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1371 UINT32 OldPackageLen
;
1373 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || String
== NULL
|| PackageList
== NULL
) {
1374 return EFI_INVALID_PARAMETER
;
1377 if (!IsHiiHandleValid (PackageList
)) {
1378 return EFI_NOT_FOUND
;
1381 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1382 PackageListNode
= NULL
;
1384 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1385 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1386 if (DatabaseRecord
->Handle
== PackageList
) {
1387 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1391 if (PackageListNode
!= NULL
) {
1392 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1393 Link
!= &PackageListNode
->StringPkgHdr
;
1394 Link
= Link
->ForwardLink
1396 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1397 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1398 OldPackageLen
= StringPackage
->StringPkgHdr
->Header
.Length
;
1399 Status
= SetStringWorker (
1403 (EFI_STRING
) String
,
1404 (EFI_FONT_INFO
*) StringFontInfo
1406 if (EFI_ERROR (Status
)) {
1409 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
- OldPackageLen
;
1415 return EFI_NOT_FOUND
;
1421 This function returns the list of supported languages, in the format specified
1422 in Appendix M of UEFI 2.1 spec.
1424 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1425 @param PackageList The package list to examine.
1426 @param Languages Points to the buffer to hold the returned string.
1427 @param LanguagesSize On entry, points to the size of the buffer pointed
1428 to by Languages, in bytes. On return, points to
1429 the length of Languages, in bytes.
1431 @retval EFI_SUCCESS The languages were returned successfully.
1432 @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.
1433 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1434 supported languages. LanguageSize is updated to
1435 contain the required size.
1436 @retval EFI_NOT_FOUND Could not find string package in specified
1443 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1444 IN EFI_HII_HANDLE PackageList
,
1445 IN OUT CHAR8
*Languages
,
1446 IN OUT UINTN
*LanguagesSize
1450 HII_DATABASE_PRIVATE_DATA
*Private
;
1451 HII_DATABASE_RECORD
*DatabaseRecord
;
1452 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1453 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1456 if (This
== NULL
|| Languages
== NULL
|| LanguagesSize
== NULL
|| PackageList
== NULL
) {
1457 return EFI_INVALID_PARAMETER
;
1459 if (!IsHiiHandleValid (PackageList
)) {
1460 return EFI_NOT_FOUND
;
1463 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1465 PackageListNode
= NULL
;
1466 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1467 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1468 if (DatabaseRecord
->Handle
== PackageList
) {
1469 PackageListNode
= DatabaseRecord
->PackageList
;
1473 if (PackageListNode
== NULL
) {
1474 return EFI_NOT_FOUND
;
1478 // Search the languages in the specified packagelist.
1481 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1482 Link
!= &PackageListNode
->StringPkgHdr
;
1483 Link
= Link
->ForwardLink
1485 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1486 ResultSize
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1487 if (ResultSize
< *LanguagesSize
) {
1488 AsciiStrCpy (Languages
, StringPackage
->StringPkgHdr
->Language
);
1489 Languages
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1490 *(Languages
- 1) = L
';';
1493 if (ResultSize
== 0) {
1494 return EFI_NOT_FOUND
;
1497 if (*LanguagesSize
< ResultSize
) {
1498 *LanguagesSize
= ResultSize
;
1499 return EFI_BUFFER_TOO_SMALL
;
1502 *(Languages
- 1) = 0;
1508 Each string package has associated with it a single primary language and zero
1509 or more secondary languages. This routine returns the secondary languages
1510 associated with a package list.
1512 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1513 @param PackageList The package list to examine.
1514 @param FirstLanguage Points to the primary language.
1515 @param SecondaryLanguages Points to the buffer to hold the returned list of
1516 secondary languages for the specified
1517 FirstLanguage. If there are no secondary
1518 languages, the function returns successfully, but
1519 this is set to NULL.
1520 @param SecondaryLanguageSize On entry, points to the size of the buffer pointed
1521 to by SecondLanguages, in bytes. On return,
1522 points to the length of SecondLanguages in bytes.
1524 @retval EFI_SUCCESS Secondary languages were correctly returned.
1525 @retval EFI_INVALID_PARAMETER FirstLanguage or SecondLanguages or
1526 SecondLanguagesSize was NULL.
1527 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondLanguagesSize is
1528 too small to hold the returned information.
1529 SecondLanguageSize is updated to hold the size of
1530 the buffer required.
1531 @retval EFI_NOT_FOUND The language specified by FirstLanguage is not
1532 present in the specified package list.
1537 HiiGetSecondaryLanguages (
1538 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1539 IN EFI_HII_HANDLE PackageList
,
1540 IN CONST CHAR8
*FirstLanguage
,
1541 IN OUT CHAR8
*SecondLanguages
,
1542 IN OUT UINTN
*SecondLanguagesSize
1547 HII_DATABASE_PRIVATE_DATA
*Private
;
1548 HII_DATABASE_RECORD
*DatabaseRecord
;
1549 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1550 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1554 if (This
== NULL
|| PackageList
== NULL
|| FirstLanguage
== NULL
) {
1555 return EFI_INVALID_PARAMETER
;
1557 if (SecondLanguages
== NULL
|| SecondLanguagesSize
== NULL
) {
1558 return EFI_INVALID_PARAMETER
;
1560 if (!IsHiiHandleValid (PackageList
)) {
1561 return EFI_NOT_FOUND
;
1564 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1568 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1569 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1570 if (DatabaseRecord
->Handle
== PackageList
) {
1571 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1572 for (Link1
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1573 Link1
!= &PackageListNode
->StringPkgHdr
;
1574 Link1
= Link1
->ForwardLink
1576 StringPackage
= CR (Link1
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1577 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) FirstLanguage
)) {
1578 Languages
= StringPackage
->StringPkgHdr
->Language
;
1580 // Language is a series of ';' terminated strings, first one is primary
1581 // language and following with other secondary languages or NULL if no
1582 // secondary languages any more.
1584 Languages
= AsciiStrStr (Languages
, ";");
1585 if (Languages
== NULL
) {
1590 ResultSize
= AsciiStrSize (Languages
);
1591 if (ResultSize
<= *SecondLanguagesSize
) {
1592 AsciiStrCpy (SecondLanguages
, Languages
);
1594 *SecondLanguagesSize
= ResultSize
;
1595 return EFI_BUFFER_TOO_SMALL
;
1604 return EFI_NOT_FOUND
;