2 Implementation for EFI_HII_STRING_PROTOCOL.
5 Copyright (c) 2007, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
19 CHAR16 mLanguageWindow
[16] = {
20 0x0000, 0x0080, 0x0100, 0x0300,
21 0x2000, 0x2080, 0x2100, 0x3000,
22 0x0080, 0x00C0, 0x0400, 0x0600,
23 0x0900, 0x3040, 0x30A0, 0xFF00
28 This function checks whether a global font info is referred by local
29 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create
30 a HII_FONT_INFO to refer it locally.
32 This is a internal function.
35 @param Private Hii database private structure.
36 @param StringPackage HII string package instance.
37 @param FontId Font identifer, which must be unique within the string package.
38 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to
39 the same EFI_FONT_INFO is permitted. Otherwise it
41 @param GlobalFontInfo Input a global font info which specify a
43 @param LocalFontInfo Output a local font info which refers to a
46 @retval TRUE Already referred before calling this function.
47 @retval FALSE Not referred before calling this function.
51 ReferFontInfoLocally (
52 IN HII_DATABASE_PRIVATE_DATA
*Private
,
53 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
55 IN BOOLEAN DuplicateEnable
,
56 IN HII_GLOBAL_FONT_INFO
*GlobalFontInfo
,
57 OUT HII_FONT_INFO
**LocalFontInfo
60 HII_FONT_INFO
*LocalFont
;
63 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& GlobalFontInfo
!= NULL
&& LocalFontInfo
!= NULL
);
65 if (!DuplicateEnable
) {
66 for (Link
= StringPackage
->FontInfoList
.ForwardLink
;
67 Link
!= &StringPackage
->FontInfoList
;
68 Link
= Link
->ForwardLink
70 LocalFont
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
71 if (LocalFont
->GlobalEntry
== &GlobalFontInfo
->Entry
) {
73 // Already referred by local font info list, return directly.
75 *LocalFontInfo
= LocalFont
;
80 // FontId identifies EFI_FONT_INFO in local string package uniquely.
81 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies
82 // EFI_FONT_INFO uniquely in whole hii database.
84 LocalFont
= (HII_FONT_INFO
*) AllocateZeroPool (sizeof (HII_FONT_INFO
));
85 ASSERT (LocalFont
!= NULL
);
87 LocalFont
->Signature
= HII_FONT_INFO_SIGNATURE
;
88 LocalFont
->FontId
= FontId
;
89 LocalFont
->GlobalEntry
= &GlobalFontInfo
->Entry
;
90 InsertTailList (&StringPackage
->FontInfoList
, &LocalFont
->Entry
);
92 *LocalFontInfo
= LocalFont
;
98 Convert Ascii string text to unicode string test.
100 This is a internal function.
103 @param StringDest Buffer to store the string text. If it is NULL,
104 only the size will be returned.
105 @param StringSrc Points to current null-terminated string.
106 @param BufferSize Length of the buffer.
108 @retval EFI_SUCCESS The string text was outputed successfully.
109 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
110 text. BufferSize is updated to the required buffer
115 ConvertToUnicodeText (
116 OUT EFI_STRING StringDest
,
118 IN OUT UINTN
*BufferSize
124 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
126 StringSize
= AsciiStrSize (StringSrc
) * 2;
127 if (*BufferSize
< StringSize
) {
128 *BufferSize
= StringSize
;
129 return EFI_BUFFER_TOO_SMALL
;
132 for (Index
= 0; Index
< AsciiStrLen (StringSrc
); Index
++) {
133 StringDest
[Index
] = (CHAR16
) StringSrc
[Index
];
136 StringDest
[Index
] = 0;
142 Calculate the size of StringSrc and output it. If StringDest is not NULL,
143 copy string text from src to dest.
145 This is a internal function.
147 @param StringDest Buffer to store the string text. If it is NULL,
148 only the size will be returned.
149 @param StringSrc Points to current null-terminated string.
150 @param BufferSize Length of the buffer.
152 @retval EFI_SUCCESS The string text was outputed successfully.
153 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string
154 text. BufferSize is updated to the required buffer
159 GetUnicodeStringTextOrSize (
160 OUT EFI_STRING StringDest
, OPTIONAL
162 IN OUT UINTN
*BufferSize
168 ASSERT (StringSrc
!= NULL
&& BufferSize
!= NULL
);
170 StringSize
= sizeof (CHAR16
);
171 StringPtr
= StringSrc
;
172 while (ReadUnaligned16 ((UINT16
*) StringPtr
) != 0) {
173 StringSize
+= sizeof (CHAR16
);
174 StringPtr
+= sizeof (CHAR16
);
177 if (*BufferSize
< StringSize
) {
178 *BufferSize
= StringSize
;
179 return EFI_BUFFER_TOO_SMALL
;
181 if (StringDest
!= NULL
) {
182 CopyMem (StringDest
, StringSrc
, StringSize
);
185 *BufferSize
= StringSize
;
191 Copy string font info to a buffer.
193 This is a internal function.
195 @param StringPackage Hii string package instance.
196 @param FontId Font identifier which is unique in a string
198 @param StringFontInfo Buffer to record the output font info. It's
199 caller's responsibility to free this buffer.
201 @retval EFI_SUCCESS The string font is outputed successfully.
202 @retval EFI_NOT_FOUND The specified font id does not exist.
207 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
209 OUT EFI_FONT_INFO
**StringFontInfo
213 HII_FONT_INFO
*FontInfo
;
214 HII_GLOBAL_FONT_INFO
*GlobalFont
;
216 ASSERT (StringFontInfo
!= NULL
&& StringPackage
!= NULL
);
218 for (Link
= StringPackage
->FontInfoList
.ForwardLink
; Link
!= &StringPackage
->FontInfoList
; Link
= Link
->ForwardLink
) {
219 FontInfo
= CR (Link
, HII_FONT_INFO
, Entry
, HII_FONT_INFO_SIGNATURE
);
220 if (FontInfo
->FontId
== FontId
) {
221 GlobalFont
= CR (FontInfo
->GlobalEntry
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
222 *StringFontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (GlobalFont
->FontInfoSize
);
223 if (*StringFontInfo
== NULL
) {
224 return EFI_OUT_OF_RESOURCES
;
226 CopyMem (*StringFontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
231 return EFI_NOT_FOUND
;
236 Parse all string blocks to find a String block specified by StringId.
237 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks
238 within this string package and backup its information.
239 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_END).
241 @param Private Hii database private structure.
242 @param StringPackage Hii string package instance.
243 @param StringId The string's id, which is unique within
245 @param BlockType Output the block type of found string block.
246 @param StringBlockAddr Output the block address of found string block.
247 @param StringTextOffset Offset, relative to the found block address, of
248 the string text information.
249 @param LastStringId Output the last string id when StringId = 0.
251 @retval EFI_SUCCESS The string text and font is retrieved
253 @retval EFI_NOT_FOUND The specified text or font info can not be found
255 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
261 IN HII_DATABASE_PRIVATE_DATA
*Private
,
262 IN HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
263 IN EFI_STRING_ID StringId
,
264 OUT UINT8
*BlockType
, OPTIONAL
265 OUT UINT8
**StringBlockAddr
, OPTIONAL
266 OUT UINTN
*StringTextOffset
, OPTIONAL
267 OUT EFI_STRING_ID
*LastStringId OPTIONAL
271 EFI_STRING_ID CurrentStringId
;
274 UINT8
*StringTextPtr
;
276 HII_FONT_INFO
*LocalFont
;
277 EFI_FONT_INFO
*FontInfo
;
278 HII_GLOBAL_FONT_INFO
*GlobalFont
;
282 EFI_HII_FONT_STYLE FontStyle
;
285 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
291 ASSERT (StringPackage
!= NULL
);
292 ASSERT (StringPackage
->Signature
== HII_STRING_PACKAGE_SIGNATURE
);
296 if (StringId
!= (EFI_STRING_ID
) (-1) && StringId
!= 0) {
297 ASSERT (BlockType
!= NULL
&& StringBlockAddr
!= NULL
&& StringTextOffset
!= NULL
);
299 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
302 ZeroMem (&Zero
, sizeof (CHAR16
));
305 // Parse the string blocks to get the string text and font.
307 BlockHdr
= StringPackage
->StringBlock
;
310 while (*BlockHdr
!= EFI_HII_SIBT_END
) {
312 case EFI_HII_SIBT_STRING_SCSU
:
313 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
314 StringTextPtr
= BlockHdr
+ Offset
;
315 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
319 case EFI_HII_SIBT_STRING_SCSU_FONT
:
320 Offset
= sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
321 StringTextPtr
= BlockHdr
+ Offset
;
322 BlockSize
+= Offset
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
326 case EFI_HII_SIBT_STRINGS_SCSU
:
327 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
328 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK
) - sizeof (UINT8
);
329 BlockSize
+= StringTextPtr
- BlockHdr
;
331 for (Index
= 0; Index
< StringCount
; Index
++) {
332 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
333 if (CurrentStringId
== StringId
) {
334 *BlockType
= *BlockHdr
;
335 *StringBlockAddr
= BlockHdr
;
336 *StringTextOffset
= StringTextPtr
- BlockHdr
;
339 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
344 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
347 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
350 StringTextPtr
= BlockHdr
+ sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK
) - sizeof (UINT8
);
351 BlockSize
+= StringTextPtr
- BlockHdr
;
353 for (Index
= 0; Index
< StringCount
; Index
++) {
354 BlockSize
+= AsciiStrSize ((CHAR8
*) StringTextPtr
);
355 if (CurrentStringId
== StringId
) {
356 *BlockType
= *BlockHdr
;
357 *StringBlockAddr
= BlockHdr
;
358 *StringTextOffset
= StringTextPtr
- BlockHdr
;
361 StringTextPtr
= StringTextPtr
+ AsciiStrSize ((CHAR8
*) StringTextPtr
);
366 case EFI_HII_SIBT_STRING_UCS2
:
367 Offset
= sizeof (EFI_HII_STRING_BLOCK
);
368 StringTextPtr
= BlockHdr
+ Offset
;
370 // Use StringSize to store the size of the specified string, including the NULL
373 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
374 BlockSize
+= Offset
+ StringSize
;
378 case EFI_HII_SIBT_STRING_UCS2_FONT
:
379 Offset
= sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
380 StringTextPtr
= BlockHdr
+ Offset
;
382 // Use StrSize to store the size of the specified string, including the NULL
385 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
386 BlockSize
+= Offset
+ StringSize
;
390 case EFI_HII_SIBT_STRINGS_UCS2
:
391 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK
) - sizeof (CHAR16
);
392 StringTextPtr
= BlockHdr
+ Offset
;
394 CopyMem (&StringCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
395 for (Index
= 0; Index
< StringCount
; Index
++) {
396 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
397 BlockSize
+= StringSize
;
398 if (CurrentStringId
== StringId
) {
399 *BlockType
= *BlockHdr
;
400 *StringBlockAddr
= BlockHdr
;
401 *StringTextOffset
= StringTextPtr
- BlockHdr
;
404 StringTextPtr
= StringTextPtr
+ StringSize
;
409 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
410 Offset
= sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK
) - sizeof (CHAR16
);
411 StringTextPtr
= BlockHdr
+ Offset
;
415 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
418 for (Index
= 0; Index
< StringCount
; Index
++) {
419 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
420 BlockSize
+= StringSize
;
421 if (CurrentStringId
== StringId
) {
422 *BlockType
= *BlockHdr
;
423 *StringBlockAddr
= BlockHdr
;
424 *StringTextOffset
= StringTextPtr
- BlockHdr
;
427 StringTextPtr
= StringTextPtr
+ StringSize
;
432 case EFI_HII_SIBT_DUPLICATE
:
433 if (CurrentStringId
== StringId
) {
435 // Incoming StringId is an id of a duplicate string block.
436 // Update the StringId to be the previous string block.
437 // Go back to the header of string block to search.
441 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
),
442 sizeof (EFI_STRING_ID
)
444 ASSERT (StringId
!= CurrentStringId
);
448 BlockSize
+= sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK
);
453 case EFI_HII_SIBT_SKIP1
:
454 SkipCount
= (UINT16
) (*(BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
)));
455 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
456 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP1_BLOCK
);
459 case EFI_HII_SIBT_SKIP2
:
460 CopyMem (&SkipCount
, BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
), sizeof (UINT16
));
461 CurrentStringId
= (UINT16
) (CurrentStringId
+ SkipCount
);
462 BlockSize
+= sizeof (EFI_HII_SIBT_SKIP2_BLOCK
);
465 case EFI_HII_SIBT_EXT1
:
468 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
471 BlockSize
+= Length8
;
474 case EFI_HII_SIBT_EXT2
:
475 CopyMem (&Ext2
, BlockHdr
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
476 if (Ext2
.BlockType2
== EFI_HII_SIBT_FONT
&& StringId
== (EFI_STRING_ID
) (-1)) {
478 // Find the relationship between global font info and the font info of
479 // this EFI_HII_SIBT_FONT block then backup its information in local package.
481 BlockHdr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
482 CopyMem (&FontId
, BlockHdr
, sizeof (UINT8
));
483 BlockHdr
+= sizeof (UINT8
);
484 CopyMem (&FontSize
, BlockHdr
, sizeof (UINT16
));
485 BlockHdr
+= sizeof (UINT16
);
486 CopyMem (&FontStyle
, BlockHdr
, sizeof (EFI_HII_FONT_STYLE
));
487 BlockHdr
+= sizeof (EFI_HII_FONT_STYLE
);
488 GetUnicodeStringTextOrSize (NULL
, BlockHdr
, &StringSize
);
490 FontInfoSize
= sizeof (EFI_FONT_INFO
) - sizeof (CHAR16
) + StringSize
;
491 FontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (FontInfoSize
);
492 if (FontInfo
== NULL
) {
493 return EFI_OUT_OF_RESOURCES
;
495 FontInfo
->FontStyle
= FontStyle
;
496 FontInfo
->FontSize
= FontSize
;
497 CopyMem (FontInfo
->FontName
, BlockHdr
, StringSize
);
500 // If find the corresponding global font info, save the relationship.
501 // Otherwise ignore this EFI_HII_SIBT_FONT block.
503 if (IsFontInfoExisted (Private
, FontInfo
, NULL
, NULL
, &GlobalFont
)) {
504 ReferFontInfoLocally (Private
, StringPackage
, FontId
, TRUE
, GlobalFont
, &LocalFont
);
508 // Since string package tool set FontId initially to 0 and increases it
509 // progressively by one, StringPackage->FondId always represents an unique
510 // and available FontId.
512 StringPackage
->FontId
++;
517 BlockSize
+= Ext2
.Length
;
521 case EFI_HII_SIBT_EXT4
:
524 BlockHdr
+ sizeof (EFI_HII_STRING_BLOCK
) + sizeof (UINT8
),
528 BlockSize
+= Length32
;
536 if (StringId
== CurrentStringId
- 1) {
537 *BlockType
= *BlockHdr
;
538 *StringBlockAddr
= BlockHdr
;
539 *StringTextOffset
= Offset
;
543 if (StringId
< CurrentStringId
- 1) {
544 return EFI_NOT_FOUND
;
547 BlockHdr
= StringPackage
->StringBlock
+ BlockSize
;
551 if (StringId
== (EFI_STRING_ID
) (-1)) {
555 if (StringId
== 0 && LastStringId
!= NULL
) {
556 *LastStringId
= CurrentStringId
;
560 return EFI_NOT_FOUND
;
565 Parse all string blocks to get a string specified by StringId.
567 This is a internal function.
569 @param Private Hii database private structure.
570 @param StringPackage Hii string package instance.
571 @param StringId The string's id, which is unique within
573 @param String Points to retrieved null-terminated string.
574 @param StringSize On entry, points to the size of the buffer pointed
575 to by String, in bytes. On return, points to the
576 length of the string, in bytes.
577 @param StringFontInfo If not NULL, allocate a buffer to record the
578 output font info. It's caller's responsibility to
581 @retval EFI_SUCCESS The string text and font is retrieved
583 @retval EFI_NOT_FOUND The specified text or font info can not be found
585 @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. The FontId 0 is the default font for those string blocks which
651 // do not specify a font identifier. If default font is not specified, return NULL.
653 if (StringFontInfo
!= NULL
) {
655 case EFI_HII_SIBT_STRING_SCSU_FONT
:
656 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
657 case EFI_HII_SIBT_STRING_UCS2_FONT
:
658 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
659 FontId
= *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
));
664 Status
= GetStringFontInfo (StringPackage
, FontId
, StringFontInfo
);
665 if (Status
== EFI_NOT_FOUND
) {
666 *StringFontInfo
= NULL
;
675 Parse all string blocks to set a String specified by StringId.
677 This is a internal function.
679 @param Private HII database driver private structure.
680 @param StringPackage HII string package instance.
681 @param StringId The string's id, which is unique within
683 @param String Points to the new null-terminated string.
684 @param StringFontInfo Points to the input font info.
686 @retval EFI_SUCCESS The string was updated successfully.
687 @retval EFI_NOT_FOUND The string specified by StringId is not in the
689 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
690 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
692 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
698 IN HII_DATABASE_PRIVATE_DATA
*Private
,
699 IN OUT HII_STRING_PACKAGE_INSTANCE
*StringPackage
,
700 IN EFI_STRING_ID StringId
,
701 IN EFI_STRING String
,
702 IN EFI_FONT_INFO
*StringFontInfo OPTIONAL
705 UINT8
*StringTextPtr
;
707 UINT8
*StringBlockAddr
;
708 UINTN StringTextOffset
;
714 HII_FONT_INFO
*LocalFont
;
715 HII_GLOBAL_FONT_INFO
*GlobalFont
;
717 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
722 ASSERT (Private
!= NULL
&& StringPackage
!= NULL
&& String
!= NULL
);
723 ASSERT (Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
725 // Find the specified string block
727 Status
= FindStringBlock (
736 if (EFI_ERROR (Status
)) {
745 // The input StringFontInfo should exist in current database if specified.
747 if (StringFontInfo
!= NULL
) {
748 if (!IsFontInfoExisted (Private
, StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
749 return EFI_INVALID_PARAMETER
;
751 Referred
= ReferFontInfoLocally (
754 StringPackage
->FontId
,
760 StringPackage
->FontId
++;
764 // Update the FontId of the specified string block to input font info.
767 case EFI_HII_SIBT_STRING_SCSU_FONT
:
768 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
769 case EFI_HII_SIBT_STRING_UCS2_FONT
:
770 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
771 *(StringBlockAddr
+ sizeof (EFI_HII_STRING_BLOCK
)) = LocalFont
->FontId
;
775 // When modify the font info of these blocks, the block type should be updated
776 // to contain font info thus the whole structure should be revised.
777 // It is recommended to use tool to modify the block type not in the code.
779 return EFI_UNSUPPORTED
;
783 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
786 // Set the string text and font.
788 StringTextPtr
= StringBlockAddr
+ StringTextOffset
;
790 case EFI_HII_SIBT_STRING_SCSU
:
791 case EFI_HII_SIBT_STRING_SCSU_FONT
:
792 case EFI_HII_SIBT_STRINGS_SCSU
:
793 case EFI_HII_SIBT_STRINGS_SCSU_FONT
:
794 BlockSize
= OldBlockSize
+ StrLen (String
);
795 BlockSize
-= AsciiStrLen ((CHAR8
*) StringTextPtr
);
796 Block
= AllocateZeroPool (BlockSize
);
798 return EFI_OUT_OF_RESOURCES
;
801 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
802 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
804 while (*String
!= 0) {
805 *BlockPtr
++ = (CHAR8
) *String
++;
810 TmpSize
= OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - AsciiStrSize ((CHAR8
*) StringTextPtr
);
813 StringTextPtr
+ AsciiStrSize ((CHAR8
*)StringTextPtr
),
817 FreePool (StringPackage
->StringBlock
);
818 StringPackage
->StringBlock
= Block
;
819 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
822 case EFI_HII_SIBT_STRING_UCS2
:
823 case EFI_HII_SIBT_STRING_UCS2_FONT
:
824 case EFI_HII_SIBT_STRINGS_UCS2
:
825 case EFI_HII_SIBT_STRINGS_UCS2_FONT
:
827 // Use StrSize to store the size of the specified string, including the NULL
830 GetUnicodeStringTextOrSize (NULL
, StringTextPtr
, &StringSize
);
832 BlockSize
= OldBlockSize
+ StrSize (String
) - StringSize
;
833 Block
= AllocateZeroPool (BlockSize
);
835 return EFI_OUT_OF_RESOURCES
;
838 CopyMem (Block
, StringPackage
->StringBlock
, StringTextPtr
- StringPackage
->StringBlock
);
839 BlockPtr
= Block
+ (StringTextPtr
- StringPackage
->StringBlock
);
841 CopyMem (BlockPtr
, String
, StrSize (String
));
842 BlockPtr
+= StrSize (String
);
846 StringTextPtr
+ StringSize
,
847 OldBlockSize
- (StringTextPtr
- StringPackage
->StringBlock
) - StringSize
850 FreePool (StringPackage
->StringBlock
);
851 StringPackage
->StringBlock
= Block
;
852 StringPackage
->StringPkgHdr
->Header
.Length
+= (UINT32
) (BlockSize
- OldBlockSize
);
856 return EFI_NOT_FOUND
;
860 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming
861 // StringFontInfo does not exist in current string package.
863 // This new block does not impact on the value of StringId.
866 if (StringFontInfo
== NULL
|| Referred
) {
870 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
871 BlockSize
= OldBlockSize
+ sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
) +
872 StrSize (GlobalFont
->FontInfo
->FontName
);
874 Block
= AllocateZeroPool (BlockSize
);
876 return EFI_OUT_OF_RESOURCES
;
880 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
881 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
882 Ext2
.Length
= (UINT16
) (BlockSize
- OldBlockSize
);
883 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
884 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
886 *BlockPtr
= LocalFont
->FontId
;
887 BlockPtr
+= sizeof (UINT8
);
888 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontSize
, sizeof (UINT16
));
889 BlockPtr
+= sizeof (UINT16
);
890 CopyMem (BlockPtr
, &GlobalFont
->FontInfo
->FontStyle
, sizeof (UINT32
));
891 BlockPtr
+= sizeof (UINT32
);
894 GlobalFont
->FontInfo
->FontName
,
895 StrSize (GlobalFont
->FontInfo
->FontName
)
897 BlockPtr
+= StrSize (GlobalFont
->FontInfo
->FontName
);
899 CopyMem (BlockPtr
, StringPackage
->StringBlock
, OldBlockSize
);
901 FreePool (StringPackage
->StringBlock
);
902 StringPackage
->StringBlock
= Block
;
903 StringPackage
->StringPkgHdr
->Header
.Length
+= Ext2
.Length
;
911 This function adds the string String to the group of strings owned by PackageList, with the
912 specified font information StringFontInfo and returns a new string id.
914 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
915 @param PackageList Handle of the package list where this string will
917 @param StringId On return, contains the new strings id, which is
918 unique within PackageList.
919 @param Language Points to the language for the new string.
920 @param LanguageName Points to the printable language name to associate
921 with the passed in Language field.If LanguageName
922 is not NULL and the string package header's
923 LanguageName associated with a given Language is
924 not zero, the LanguageName being passed in will
926 @param String Points to the new null-terminated string.
927 @param StringFontInfo Points to the new string's font information or
928 NULL if the string should have the default system
929 font, size and style.
931 @retval EFI_SUCCESS The new string was added successfully.
932 @retval EFI_NOT_FOUND The specified PackageList could not be found in
934 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
935 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is
937 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
944 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
945 IN EFI_HII_HANDLE PackageList
,
946 OUT EFI_STRING_ID
*StringId
,
947 IN CONST CHAR8
*Language
,
948 IN CONST CHAR16
*LanguageName
, OPTIONAL
949 IN CONST EFI_STRING String
,
950 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
956 HII_DATABASE_PRIVATE_DATA
*Private
;
957 HII_DATABASE_RECORD
*DatabaseRecord
;
958 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
959 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
965 UINT32 Ucs2BlockSize
;
966 UINT32 FontBlockSize
;
967 UINT32 Ucs2FontBlockSize
;
968 EFI_HII_SIBT_EXT2_BLOCK Ext2
;
969 HII_FONT_INFO
*LocalFont
;
970 HII_GLOBAL_FONT_INFO
*GlobalFont
;
972 if (This
== NULL
|| String
== NULL
|| StringId
== NULL
|| Language
== NULL
|| PackageList
== NULL
) {
973 return EFI_INVALID_PARAMETER
;
976 if (!IsHiiHandleValid (PackageList
)) {
977 return EFI_NOT_FOUND
;
980 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
984 // If StringFontInfo specify a paritcular font, it should exist in current database.
986 if (StringFontInfo
!= NULL
) {
987 if (!IsFontInfoExisted (Private
, (EFI_FONT_INFO
*) StringFontInfo
, NULL
, NULL
, &GlobalFont
)) {
988 return EFI_INVALID_PARAMETER
;
993 // Get the matching package list.
995 PackageListNode
= NULL
;
996 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
997 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
998 if (DatabaseRecord
->Handle
== PackageList
) {
999 PackageListNode
= DatabaseRecord
->PackageList
;
1003 if (PackageListNode
== NULL
) {
1004 return EFI_NOT_FOUND
;
1008 // Try to get the matching string package. Create a new string package when failed.
1010 StringPackage
= NULL
;
1012 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1013 Link
!= &PackageListNode
->StringPkgHdr
;
1014 Link
= Link
->ForwardLink
1016 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1017 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1025 // LanguageName is required to create a new string package.
1027 if (LanguageName
== NULL
) {
1028 return EFI_INVALID_PARAMETER
;
1031 StringPackage
= AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE
));
1032 if (StringPackage
== NULL
) {
1033 return EFI_OUT_OF_RESOURCES
;
1036 StringPackage
->Signature
= HII_STRING_PACKAGE_SIGNATURE
;
1037 StringPackage
->FontId
= 0;
1038 InitializeListHead (&StringPackage
->FontInfoList
);
1041 // Fill in the string package header
1043 HeaderSize
= (UINT32
) (AsciiStrSize ((CHAR8
*) Language
) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR
));
1044 StringPackage
->StringPkgHdr
= AllocateZeroPool (HeaderSize
);
1045 if (StringPackage
->StringPkgHdr
== NULL
) {
1046 FreePool (StringPackage
);
1047 return EFI_OUT_OF_RESOURCES
;
1049 StringPackage
->StringPkgHdr
->Header
.Type
= EFI_HII_PACKAGE_STRINGS
;
1050 StringPackage
->StringPkgHdr
->HdrSize
= HeaderSize
;
1051 StringPackage
->StringPkgHdr
->StringInfoOffset
= HeaderSize
;
1052 CopyMem (StringPackage
->StringPkgHdr
->LanguageWindow
, mLanguageWindow
, 16 * sizeof (CHAR16
));;
1053 StringPackage
->StringPkgHdr
->LanguageName
= 1;
1054 AsciiStrCpy (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
);
1057 // Calculate the length of the string blocks, including string block to record
1058 // printable language full name and EFI_HII_SIBT_END_BLOCK.
1060 Ucs2BlockSize
= (UINT32
) (StrSize ((CHAR16
*) LanguageName
) +
1061 sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
) - sizeof (CHAR16
));
1063 BlockSize
= Ucs2BlockSize
+ sizeof (EFI_HII_SIBT_END_BLOCK
);
1064 StringPackage
->StringBlock
= (UINT8
*) AllocateZeroPool (BlockSize
);
1065 if (StringPackage
->StringBlock
== NULL
) {
1066 FreePool (StringPackage
->StringPkgHdr
);
1067 FreePool (StringPackage
);
1068 return EFI_OUT_OF_RESOURCES
;
1072 // Insert the string block of printable language full name
1074 BlockPtr
= StringPackage
->StringBlock
;
1075 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1076 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1077 CopyMem (BlockPtr
, (EFI_STRING
) LanguageName
, StrSize ((EFI_STRING
) LanguageName
));
1078 BlockPtr
+= StrSize ((EFI_STRING
) LanguageName
);
1081 // Insert the end block
1083 *BlockPtr
= EFI_HII_SIBT_END
;
1086 // Append this string package node to string package array in this package list.
1088 StringPackage
->StringPkgHdr
->Header
.Length
= HeaderSize
+ BlockSize
;
1089 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
;
1090 InsertTailList (&PackageListNode
->StringPkgHdr
, &StringPackage
->StringEntry
);
1095 // Create a string block and corresponding font block if exists, then append them
1096 // to the end of the string package.
1098 Status
= FindStringBlock (
1107 if (EFI_ERROR (Status
)) {
1111 OldBlockSize
= StringPackage
->StringPkgHdr
->Header
.Length
- StringPackage
->StringPkgHdr
->HdrSize
;
1113 if (StringFontInfo
== NULL
) {
1115 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.
1118 Ucs2BlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK
)
1121 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2BlockSize
);
1122 if (StringBlock
== NULL
) {
1123 return EFI_OUT_OF_RESOURCES
;
1126 // Copy original string blocks, except the EFI_HII_SIBT_END.
1128 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1130 // Create a EFI_HII_SIBT_STRING_UCS2 block
1132 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1133 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2
;
1134 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1135 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1136 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1139 // Append a EFI_HII_SIBT_END block to the end.
1141 *BlockPtr
= EFI_HII_SIBT_END
;
1142 FreePool (StringPackage
->StringBlock
);
1143 StringPackage
->StringBlock
= StringBlock
;
1144 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2BlockSize
;
1145 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2BlockSize
;
1149 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK
1150 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block
1151 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING
1152 // _UCS2_FONT block.
1154 Ucs2FontBlockSize
= (UINT32
) (StrSize (String
) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
) -
1156 if (ReferFontInfoLocally (Private
, StringPackage
, StringPackage
->FontId
, FALSE
, GlobalFont
, &LocalFont
)) {
1158 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.
1160 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ Ucs2FontBlockSize
);
1161 if (StringBlock
== NULL
) {
1162 return EFI_OUT_OF_RESOURCES
;
1165 // Copy original string blocks, except the EFI_HII_SIBT_END.
1167 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1169 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1171 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1172 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1173 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1174 *BlockPtr
= LocalFont
->FontId
;
1175 BlockPtr
+= sizeof (UINT8
);
1176 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1177 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1180 // Append a EFI_HII_SIBT_END block to the end.
1182 *BlockPtr
= EFI_HII_SIBT_END
;
1183 FreePool (StringPackage
->StringBlock
);
1184 StringPackage
->StringBlock
= StringBlock
;
1185 StringPackage
->StringPkgHdr
->Header
.Length
+= Ucs2FontBlockSize
;
1186 PackageListNode
->PackageListHdr
.PackageLength
+= Ucs2FontBlockSize
;
1190 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so
1191 // create a EFI_HII_SIBT_FONT block to record the font info, then generate
1192 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.
1194 FontBlockSize
= (UINT32
) (StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
) +
1195 sizeof (EFI_HII_SIBT_FONT_BLOCK
) - sizeof (CHAR16
));
1196 StringBlock
= (UINT8
*) AllocateZeroPool (OldBlockSize
+ FontBlockSize
+ Ucs2FontBlockSize
);
1197 if (StringBlock
== NULL
) {
1198 return EFI_OUT_OF_RESOURCES
;
1201 // Copy original string blocks, except the EFI_HII_SIBT_END.
1203 CopyMem (StringBlock
, StringPackage
->StringBlock
, OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
));
1206 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string
1207 // package instance for future reference.
1209 BlockPtr
= StringBlock
+ OldBlockSize
- sizeof (EFI_HII_SIBT_END_BLOCK
);
1211 Ext2
.Header
.BlockType
= EFI_HII_SIBT_EXT2
;
1212 Ext2
.BlockType2
= EFI_HII_SIBT_FONT
;
1213 Ext2
.Length
= (UINT16
) FontBlockSize
;
1214 CopyMem (BlockPtr
, &Ext2
, sizeof (EFI_HII_SIBT_EXT2_BLOCK
));
1215 BlockPtr
+= sizeof (EFI_HII_SIBT_EXT2_BLOCK
);
1217 *BlockPtr
= LocalFont
->FontId
;
1218 BlockPtr
+= sizeof (UINT8
);
1219 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontSize
, sizeof (UINT16
));
1220 BlockPtr
+= sizeof (UINT16
);
1221 CopyMem (BlockPtr
, &((EFI_FONT_INFO
*) StringFontInfo
)->FontStyle
, sizeof (EFI_HII_FONT_STYLE
));
1222 BlockPtr
+= sizeof (EFI_HII_FONT_STYLE
);
1225 &((EFI_FONT_INFO
*) StringFontInfo
)->FontName
,
1226 StrSize (((EFI_FONT_INFO
*) StringFontInfo
)->FontName
)
1230 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK
1232 *BlockPtr
= EFI_HII_SIBT_STRING_UCS2_FONT
;
1233 BlockPtr
+= sizeof (EFI_HII_STRING_BLOCK
);
1234 *BlockPtr
= LocalFont
->FontId
;
1235 BlockPtr
+= sizeof (UINT8
);
1236 CopyMem (BlockPtr
, (EFI_STRING
) String
, StrSize ((EFI_STRING
) String
));
1237 BlockPtr
+= StrSize ((EFI_STRING
) String
);
1240 // Append a EFI_HII_SIBT_END block to the end.
1242 *BlockPtr
= EFI_HII_SIBT_END
;
1243 FreePool (StringPackage
->StringBlock
);
1244 StringPackage
->StringBlock
= StringBlock
;
1245 StringPackage
->StringPkgHdr
->Header
.Length
+= FontBlockSize
+ Ucs2FontBlockSize
;
1246 PackageListNode
->PackageListHdr
.PackageLength
+= FontBlockSize
+ Ucs2FontBlockSize
;
1249 // Increase the FontId to make it unique since we already add
1250 // a EFI_HII_SIBT_FONT block to this string package.
1252 StringPackage
->FontId
++;
1257 // Trigger any registered notification function
1260 return InvokeRegisteredFunction (
1262 EFI_HII_DATABASE_NOTIFY_NEW_PACK
,
1263 (VOID
*) StringPackage
,
1264 EFI_HII_PACKAGE_STRINGS
,
1274 This function retrieves the string specified by StringId which is associated
1275 with the specified PackageList in the language Language and copies it into
1276 the buffer specified by String.
1278 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1279 @param Language Points to the language for the retrieved string.
1280 @param PackageList The package list in the HII database to search for
1281 the specified string.
1282 @param StringId The string's id, which is unique within
1284 @param String Points to the new null-terminated string.
1285 @param StringSize On entry, points to the size of the buffer pointed
1286 to by String, in bytes. On return, points to the
1287 length of the string, in bytes.
1288 @param StringFontInfo If not NULL, points to the string's font
1289 information. It's caller's responsibility to free
1292 @retval EFI_SUCCESS The string was returned successfully.
1293 @retval EFI_NOT_FOUND The string specified by StringId is not available.
1294 @retval EFI_NOT_FOUND The string specified by StringId is available but
1295 not in the specified language.
1296 The specified PackageList is not in the database.
1297 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but
1298 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to
1300 @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.
1301 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
1308 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1309 IN CONST CHAR8
*Language
,
1310 IN EFI_HII_HANDLE PackageList
,
1311 IN EFI_STRING_ID StringId
,
1312 OUT EFI_STRING String
,
1313 IN OUT UINTN
*StringSize
,
1314 OUT EFI_FONT_INFO
**StringFontInfo OPTIONAL
1319 HII_DATABASE_PRIVATE_DATA
*Private
;
1320 HII_DATABASE_RECORD
*DatabaseRecord
;
1321 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1322 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1324 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || StringSize
== NULL
|| PackageList
== NULL
) {
1325 return EFI_INVALID_PARAMETER
;
1328 if (String
== NULL
&& *StringSize
!= 0) {
1329 return EFI_INVALID_PARAMETER
;
1332 if (!IsHiiHandleValid (PackageList
)) {
1333 return EFI_NOT_FOUND
;
1336 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1337 PackageListNode
= NULL
;
1339 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1340 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1341 if (DatabaseRecord
->Handle
== PackageList
) {
1342 PackageListNode
= DatabaseRecord
->PackageList
;
1347 if (PackageListNode
!= NULL
) {
1349 // First search: to match the StringId in the specified language.
1351 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1352 Link
!= &PackageListNode
->StringPkgHdr
;
1353 Link
= Link
->ForwardLink
1355 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1356 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1357 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1358 if (Status
!= EFI_NOT_FOUND
) {
1364 // Second search: to match the StringId in other available languages if exist.
1366 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1367 Link
!= &PackageListNode
->StringPkgHdr
;
1368 Link
= Link
->ForwardLink
1370 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1371 Status
= GetStringWorker (Private
, StringPackage
, StringId
, String
, StringSize
, StringFontInfo
);
1372 if (!EFI_ERROR (Status
)) {
1373 return EFI_INVALID_LANGUAGE
;
1378 return EFI_NOT_FOUND
;
1384 This function updates the string specified by StringId in the specified PackageList to the text
1385 specified by String and, optionally, the font information specified by StringFontInfo.
1387 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1388 @param PackageList The package list containing the strings.
1389 @param StringId The string's id, which is unique within
1391 @param Language Points to the language for the updated string.
1392 @param String Points to the new null-terminated string.
1393 @param StringFontInfo Points to the string's font information or NULL if
1394 the string font information is not changed.
1396 @retval EFI_SUCCESS The string was updated successfully.
1397 @retval EFI_NOT_FOUND The string specified by StringId is not in the
1399 @retval EFI_INVALID_PARAMETER The String or Language was NULL.
1400 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in
1402 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
1409 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1410 IN EFI_HII_HANDLE PackageList
,
1411 IN EFI_STRING_ID StringId
,
1412 IN CONST CHAR8
*Language
,
1413 IN CONST EFI_STRING String
,
1414 IN CONST EFI_FONT_INFO
*StringFontInfo OPTIONAL
1419 HII_DATABASE_PRIVATE_DATA
*Private
;
1420 HII_DATABASE_RECORD
*DatabaseRecord
;
1421 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1422 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1423 UINT32 OldPackageLen
;
1425 if (This
== NULL
|| Language
== NULL
|| StringId
< 1 || String
== NULL
|| PackageList
== NULL
) {
1426 return EFI_INVALID_PARAMETER
;
1429 if (!IsHiiHandleValid (PackageList
)) {
1430 return EFI_NOT_FOUND
;
1433 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1434 PackageListNode
= NULL
;
1436 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1437 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1438 if (DatabaseRecord
->Handle
== PackageList
) {
1439 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1443 if (PackageListNode
!= NULL
) {
1444 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1445 Link
!= &PackageListNode
->StringPkgHdr
;
1446 Link
= Link
->ForwardLink
1448 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1449 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) Language
)) {
1450 OldPackageLen
= StringPackage
->StringPkgHdr
->Header
.Length
;
1451 Status
= SetStringWorker (
1455 (EFI_STRING
) String
,
1456 (EFI_FONT_INFO
*) StringFontInfo
1458 if (EFI_ERROR (Status
)) {
1461 PackageListNode
->PackageListHdr
.PackageLength
+= StringPackage
->StringPkgHdr
->Header
.Length
- OldPackageLen
;
1467 return EFI_NOT_FOUND
;
1473 This function returns the list of supported languages, in the format specified
1474 in Appendix M of UEFI 2.1 spec.
1476 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1477 @param PackageList The package list to examine.
1478 @param Languages Points to the buffer to hold the returned string.
1479 @param LanguagesSize On entry, points to the size of the buffer pointed
1480 to by Languages, in bytes. On return, points to
1481 the length of Languages, in bytes.
1483 @retval EFI_SUCCESS The languages were returned successfully.
1484 @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.
1485 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of
1486 supported languages. LanguageSize is updated to
1487 contain the required size.
1488 @retval EFI_NOT_FOUND Could not find string package in specified
1495 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1496 IN EFI_HII_HANDLE PackageList
,
1497 IN OUT CHAR8
*Languages
,
1498 IN OUT UINTN
*LanguagesSize
1502 HII_DATABASE_PRIVATE_DATA
*Private
;
1503 HII_DATABASE_RECORD
*DatabaseRecord
;
1504 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1505 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1508 if (This
== NULL
|| Languages
== NULL
|| LanguagesSize
== NULL
|| PackageList
== NULL
) {
1509 return EFI_INVALID_PARAMETER
;
1511 if (!IsHiiHandleValid (PackageList
)) {
1512 return EFI_NOT_FOUND
;
1515 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1517 PackageListNode
= NULL
;
1518 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1519 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1520 if (DatabaseRecord
->Handle
== PackageList
) {
1521 PackageListNode
= DatabaseRecord
->PackageList
;
1525 if (PackageListNode
== NULL
) {
1526 return EFI_NOT_FOUND
;
1530 // Search the languages in the specified packagelist.
1533 for (Link
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1534 Link
!= &PackageListNode
->StringPkgHdr
;
1535 Link
= Link
->ForwardLink
1537 StringPackage
= CR (Link
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1538 ResultSize
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1539 if (ResultSize
< *LanguagesSize
) {
1540 AsciiStrCpy (Languages
, StringPackage
->StringPkgHdr
->Language
);
1541 Languages
+= AsciiStrSize (StringPackage
->StringPkgHdr
->Language
);
1542 *(Languages
- 1) = L
';';
1545 if (ResultSize
== 0) {
1546 return EFI_NOT_FOUND
;
1549 if (*LanguagesSize
< ResultSize
) {
1550 *LanguagesSize
= ResultSize
;
1551 return EFI_BUFFER_TOO_SMALL
;
1554 *(Languages
- 1) = 0;
1560 Each string package has associated with it a single primary language and zero
1561 or more secondary languages. This routine returns the secondary languages
1562 associated with a package list.
1564 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.
1565 @param PackageList The package list to examine.
1566 @param FirstLanguage Points to the primary language.
1567 @param SecondaryLanguages Points to the buffer to hold the returned list of
1568 secondary languages for the specified
1569 FirstLanguage. If there are no secondary
1570 languages, the function returns successfully, but
1571 this is set to NULL.
1572 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed
1573 to by SecondaryLanguages, in bytes. On return,
1574 points to the length of SecondaryLanguages in bytes.
1576 @retval EFI_SUCCESS Secondary languages were correctly returned.
1577 @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or
1578 SecondaryLanguagesSize was NULL.
1579 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is
1580 too small to hold the returned information.
1581 SecondLanguageSize is updated to hold the size of
1582 the buffer required.
1583 @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not
1584 present in the specified package list.
1585 @retval EFI_NOT_FOUND The specified PackageList is not in the Database.
1590 HiiGetSecondaryLanguages (
1591 IN CONST EFI_HII_STRING_PROTOCOL
*This
,
1592 IN EFI_HII_HANDLE PackageList
,
1593 IN CONST CHAR8
*FirstLanguage
,
1594 IN OUT CHAR8
*SecondaryLanguages
,
1595 IN OUT UINTN
*SecondaryLanguagesSize
1600 HII_DATABASE_PRIVATE_DATA
*Private
;
1601 HII_DATABASE_RECORD
*DatabaseRecord
;
1602 HII_DATABASE_PACKAGE_LIST_INSTANCE
*PackageListNode
;
1603 HII_STRING_PACKAGE_INSTANCE
*StringPackage
;
1607 if (This
== NULL
|| PackageList
== NULL
|| FirstLanguage
== NULL
) {
1608 return EFI_INVALID_PARAMETER
;
1610 if (SecondaryLanguages
== NULL
|| SecondaryLanguagesSize
== NULL
) {
1611 return EFI_INVALID_PARAMETER
;
1613 if (!IsHiiHandleValid (PackageList
)) {
1614 return EFI_NOT_FOUND
;
1617 Private
= HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1619 PackageListNode
= NULL
;
1620 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
1621 DatabaseRecord
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
1622 if (DatabaseRecord
->Handle
== PackageList
) {
1623 PackageListNode
= (HII_DATABASE_PACKAGE_LIST_INSTANCE
*) (DatabaseRecord
->PackageList
);
1627 if (PackageListNode
== NULL
) {
1628 return EFI_NOT_FOUND
;
1633 for (Link1
= PackageListNode
->StringPkgHdr
.ForwardLink
;
1634 Link1
!= &PackageListNode
->StringPkgHdr
;
1635 Link1
= Link1
->ForwardLink
1637 StringPackage
= CR (Link1
, HII_STRING_PACKAGE_INSTANCE
, StringEntry
, HII_STRING_PACKAGE_SIGNATURE
);
1638 if (R8_EfiLibCompareLanguage (StringPackage
->StringPkgHdr
->Language
, (CHAR8
*) FirstLanguage
)) {
1639 Languages
= StringPackage
->StringPkgHdr
->Language
;
1641 // Language is a series of ';' terminated strings, first one is primary
1642 // language and following with other secondary languages or NULL if no
1643 // secondary languages any more.
1645 Languages
= AsciiStrStr (Languages
, ";");
1646 if (Languages
== NULL
) {
1651 ResultSize
= AsciiStrSize (Languages
);
1652 if (ResultSize
<= *SecondaryLanguagesSize
) {
1653 AsciiStrCpy (SecondaryLanguages
, Languages
);
1655 *SecondaryLanguagesSize
= ResultSize
;
1656 return EFI_BUFFER_TOO_SMALL
;
1663 return EFI_INVALID_LANGUAGE
;