2 BDS Lib functions which contain all the code to connect console device
4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalBdsLib.h"
16 #include <IndustryStandard/Bmp.h>
20 Check if we need to save the EFI variable with "ConVarName" as name
22 If ConVarName is NULL, then ASSERT().
24 @param ConVarName The name of the EFI variable.
26 @retval TRUE Set the EFI variable as NV type.
27 @retval FALSE EFI variable as NV type can be set NonNV.
36 ASSERT (ConVarName
!= NULL
);
41 // If the variable includes "Dev" at last, we consider
42 // it does not support NV attribute.
44 while (*Ptr
!= L
'\0') {
48 if (((INTN
)((UINTN
)Ptr
- (UINTN
)ConVarName
) / sizeof (CHAR16
)) <= 3) {
52 if ((*(Ptr
- 3) == 'D') && (*(Ptr
- 2) == 'e') && (*(Ptr
- 1) == 'v')) {
60 Fill console handle in System Table if there are no valid console handle in.
62 Firstly, check the validation of console handle in System Table. If it is invalid,
63 update it by the first console device handle from EFI console variable.
65 @param VarName The name of the EFI console variable.
66 @param ConsoleGuid Specified Console protocol GUID.
67 @param ConsoleHandle On IN, console handle in System Table to be checked.
68 On OUT, new console hanlde in system table.
69 @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked.
70 On OUT, new console protocol on new console hanlde in system table.
72 @retval TRUE System Table has been updated.
73 @retval FALSE System Table hasn't been updated.
77 UpdateSystemTableConsole (
79 IN EFI_GUID
*ConsoleGuid
,
80 IN OUT EFI_HANDLE
*ConsoleHandle
,
81 IN OUT VOID
**ProtocolInterface
86 EFI_DEVICE_PATH_PROTOCOL
*FullDevicePath
;
87 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
88 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
92 ASSERT (VarName
!= NULL
);
93 ASSERT (ConsoleHandle
!= NULL
);
94 ASSERT (ConsoleGuid
!= NULL
);
95 ASSERT (ProtocolInterface
!= NULL
);
97 if (*ConsoleHandle
!= NULL
) {
98 Status
= gBS
->HandleProtocol (
103 if (Status
== EFI_SUCCESS
&& Interface
== *ProtocolInterface
) {
105 // If ConsoleHandle is valid and console protocol on this handle also
106 // also matched, just return.
113 // Get all possible consoles device path from EFI variable
115 VarConsole
= BdsLibGetVariableAndSize (
117 &gEfiGlobalVariableGuid
,
120 if (VarConsole
== NULL
) {
122 // If there is no any console device, just return.
127 FullDevicePath
= VarConsole
;
131 // Check every instance of the console variable
133 Instance
= GetNextDevicePathInstance (&VarConsole
, &DevicePathSize
);
134 if (Instance
== NULL
) {
135 FreePool (FullDevicePath
);
140 // Find console device handle by device path instance
142 Status
= gBS
->LocateDevicePath (
147 if (!EFI_ERROR (Status
)) {
149 // Get the console protocol on this console device handle
151 Status
= gBS
->HandleProtocol (
156 if (!EFI_ERROR (Status
)) {
158 // Update new console handle in System Table.
160 *ConsoleHandle
= NewHandle
;
161 *ProtocolInterface
= Interface
;
166 } while (Instance
!= NULL
);
169 // No any available console devcie found.
175 This function update console variable based on ConVarName, it can
176 add or remove one specific console device path from the variable
178 @param ConVarName Console related variable name, ConIn, ConOut,
180 @param CustomizedConDevicePath The console device path which will be added to
181 the console variable ConVarName, this parameter
182 can not be multi-instance.
183 @param ExclusiveDevicePath The console device path which will be removed
184 from the console variable ConVarName, this
185 parameter can not be multi-instance.
187 @retval EFI_UNSUPPORTED The added device path is same to the removed one.
188 @retval EFI_SUCCESS Success add or remove the device path from the
194 BdsLibUpdateConsoleVariable (
195 IN CHAR16
*ConVarName
,
196 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
197 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
201 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
202 UINTN DevicePathSize
;
203 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
204 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
211 // Notes: check the device path point, here should check
212 // with compare memory
214 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
215 return EFI_UNSUPPORTED
;
218 // Delete the ExclusiveDevicePath from current default console
220 VarConsole
= BdsLibGetVariableAndSize (
222 &gEfiGlobalVariableGuid
,
227 // Initialize NewDevicePath
229 NewDevicePath
= VarConsole
;
232 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
233 // In the end, NewDevicePath is the final device path.
235 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
236 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
239 // Try to append customized device path to NewDevicePath.
241 if (CustomizedConDevicePath
!= NULL
) {
242 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
244 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
246 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
248 // In the first check, the default console variable will be _ModuleEntryPoint,
249 // just append current customized device path
251 TempNewDevicePath
= NewDevicePath
;
252 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
253 if (TempNewDevicePath
!= NULL
) {
254 FreePool(TempNewDevicePath
);
260 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
262 if (IsNvNeed(ConVarName
)) {
264 // ConVarName has NV attribute.
266 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
269 // ConVarName does not have NV attribute.
271 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
275 // Finally, Update the variable of the default console by NewDevicePath
277 DevicePathSize
= GetDevicePathSize (NewDevicePath
);
278 Status
= gRT
->SetVariable (
280 &gEfiGlobalVariableGuid
,
285 if ((DevicePathSize
== 0) && (Status
== EFI_NOT_FOUND
)) {
286 Status
= EFI_SUCCESS
;
288 ASSERT_EFI_ERROR (Status
);
290 if (VarConsole
== NewDevicePath
) {
291 if (VarConsole
!= NULL
) {
292 FreePool(VarConsole
);
295 if (VarConsole
!= NULL
) {
296 FreePool(VarConsole
);
298 if (NewDevicePath
!= NULL
) {
299 FreePool(NewDevicePath
);
309 Connect the console device base on the variable ConVarName, if
310 device path of the ConVarName is multi-instance device path, if
311 anyone of the instances is connected success, then this function
314 @param ConVarName Console related variable name, ConIn, ConOut,
317 @retval EFI_NOT_FOUND There is not any console devices connected
319 @retval EFI_SUCCESS Success connect any one instance of the console
320 device path base on the variable ConVarName.
325 BdsLibConnectConsoleVariable (
326 IN CHAR16
*ConVarName
330 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
332 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
333 EFI_DEVICE_PATH_PROTOCOL
*Next
;
334 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
338 Status
= EFI_SUCCESS
;
342 // Check if the console variable exist
344 StartDevicePath
= BdsLibGetVariableAndSize (
346 &gEfiGlobalVariableGuid
,
349 if (StartDevicePath
== NULL
) {
350 return EFI_UNSUPPORTED
;
353 CopyOfDevicePath
= StartDevicePath
;
356 // Check every instance of the console variable
358 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
359 if (Instance
== NULL
) {
360 FreePool (StartDevicePath
);
361 return EFI_UNSUPPORTED
;
365 while (!IsDevicePathEndType (Next
)) {
366 Next
= NextDevicePathNode (Next
);
369 SetDevicePathEndNode (Next
);
371 // Connect the USB console
372 // USB console device path is a short-form device path that
373 // starts with the first element being a USB WWID
374 // or a USB Class device path
376 if ((DevicePathType (Instance
) == MESSAGING_DEVICE_PATH
) &&
377 ((DevicePathSubType (Instance
) == MSG_USB_CLASS_DP
)
378 || (DevicePathSubType (Instance
) == MSG_USB_WWID_DP
)
380 Status
= BdsLibConnectUsbDevByShortFormDP (0xFF, Instance
);
381 if (!EFI_ERROR (Status
)) {
386 // Connect the instance device path
388 Status
= BdsLibConnectDevicePath (Instance
);
389 if (EFI_ERROR (Status
)) {
391 // Delete the instance from the console varialbe
393 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
399 } while (CopyOfDevicePath
!= NULL
);
401 FreePool (StartDevicePath
);
404 return EFI_NOT_FOUND
;
412 This function will search every simpletext device in current system,
413 and make every simpletext device as pertantial console device.
418 BdsLibConnectAllConsoles (
423 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
425 EFI_HANDLE
*HandleBuffer
;
430 ConDevicePath
= NULL
;
433 // Update all the console variables
435 gBS
->LocateHandleBuffer (
437 &gEfiSimpleTextInProtocolGuid
,
443 for (Index
= 0; Index
< HandleCount
; Index
++) {
444 gBS
->HandleProtocol (
446 &gEfiDevicePathProtocolGuid
,
447 (VOID
**) &ConDevicePath
449 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
452 if (HandleBuffer
!= NULL
) {
453 FreePool(HandleBuffer
);
457 gBS
->LocateHandleBuffer (
459 &gEfiSimpleTextOutProtocolGuid
,
464 for (Index
= 0; Index
< HandleCount
; Index
++) {
465 gBS
->HandleProtocol (
467 &gEfiDevicePathProtocolGuid
,
468 (VOID
**) &ConDevicePath
470 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
471 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
474 if (HandleBuffer
!= NULL
) {
475 FreePool(HandleBuffer
);
479 // Connect all console variables
481 BdsLibConnectAllDefaultConsoles ();
486 This function will connect console device base on the console
487 device variable ConIn, ConOut and ErrOut.
489 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
490 been connected success.
491 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
496 BdsLibConnectAllDefaultConsoles (
501 BOOLEAN SystemTableUpdated
;
504 // Connect all default console variables
508 // It seems impossible not to have any ConOut device on platform,
509 // so we check the status here.
511 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
512 if (EFI_ERROR (Status
)) {
517 // Insert the performance probe for Console Out
519 PERF_START (NULL
, "ConOut", "BDS", 1);
520 PERF_END (NULL
, "ConOut", "BDS", 0);
523 // Because possibly the platform is legacy free, in such case,
524 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
525 // so we need not check the status.
527 BdsLibConnectConsoleVariable (L
"ConIn");
530 // The _ModuleEntryPoint err out var is legal.
532 BdsLibConnectConsoleVariable (L
"ErrOut");
534 SystemTableUpdated
= FALSE
;
536 // Fill console handles in System Table if no console device assignd.
538 if (UpdateSystemTableConsole (L
"ConIn", &gEfiSimpleTextInProtocolGuid
, &gST
->ConsoleInHandle
, (VOID
**) &gST
->ConIn
)) {
539 SystemTableUpdated
= TRUE
;
541 if (UpdateSystemTableConsole (L
"ConOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->ConsoleOutHandle
, (VOID
**) &gST
->ConOut
)) {
542 SystemTableUpdated
= TRUE
;
544 if (UpdateSystemTableConsole (L
"ErrOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->StandardErrorHandle
, (VOID
**) &gST
->StdErr
)) {
545 SystemTableUpdated
= TRUE
;
548 if (SystemTableUpdated
) {
550 // Update the CRC32 in the EFI System Table header
553 gBS
->CalculateCrc32 (
565 Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
566 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
567 buffer is passed in it will be used if it is big enough.
569 @param BmpImage Pointer to BMP file
570 @param BmpImageSize Number of bytes in BmpImage
571 @param GopBlt Buffer containing GOP version of BmpImage.
572 @param GopBltSize Size of GopBlt in bytes.
573 @param PixelHeight Height of GopBlt/BmpImage in pixels
574 @param PixelWidth Width of GopBlt/BmpImage in pixels
576 @retval EFI_SUCCESS GopBlt and GopBltSize are returned.
577 @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
578 @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
579 GopBltSize will contain the required size.
580 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
586 IN UINTN BmpImageSize
,
587 IN OUT VOID
**GopBlt
,
588 IN OUT UINTN
*GopBltSize
,
589 OUT UINTN
*PixelHeight
,
590 OUT UINTN
*PixelWidth
595 BMP_IMAGE_HEADER
*BmpHeader
;
596 BMP_COLOR_MAP
*BmpColorMap
;
597 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
598 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
599 UINT64 BltBufferSize
;
604 UINT32 DataSizePerLine
;
608 if (sizeof (BMP_IMAGE_HEADER
) > BmpImageSize
) {
609 return EFI_INVALID_PARAMETER
;
612 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
614 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
615 return EFI_UNSUPPORTED
;
619 // Doesn't support compress.
621 if (BmpHeader
->CompressionType
!= 0) {
622 return EFI_UNSUPPORTED
;
626 // Only support BITMAPINFOHEADER format.
627 // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER
629 if (BmpHeader
->HeaderSize
!= sizeof (BMP_IMAGE_HEADER
) - OFFSET_OF(BMP_IMAGE_HEADER
, HeaderSize
)) {
630 return EFI_UNSUPPORTED
;
634 // The data size in each line must be 4 byte alignment.
636 DataSizePerLine
= ((BmpHeader
->PixelWidth
* BmpHeader
->BitPerPixel
+ 31) >> 3) & (~0x3);
637 BltBufferSize
= MultU64x32 (DataSizePerLine
, BmpHeader
->PixelHeight
);
638 if (BltBufferSize
> (UINT32
) ~0) {
639 return EFI_INVALID_PARAMETER
;
642 if ((BmpHeader
->Size
!= BmpImageSize
) ||
643 (BmpHeader
->Size
< BmpHeader
->ImageOffset
) ||
644 (BmpHeader
->Size
- BmpHeader
->ImageOffset
!= BmpHeader
->PixelHeight
* DataSizePerLine
)) {
645 return EFI_INVALID_PARAMETER
;
649 // Calculate Color Map offset in the image.
652 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
653 if (BmpHeader
->ImageOffset
< sizeof (BMP_IMAGE_HEADER
)) {
654 return EFI_INVALID_PARAMETER
;
657 if (BmpHeader
->ImageOffset
> sizeof (BMP_IMAGE_HEADER
)) {
658 switch (BmpHeader
->BitPerPixel
) {
672 if (BmpHeader
->ImageOffset
- sizeof (BMP_IMAGE_HEADER
) != sizeof (BMP_COLOR_MAP
) * ColorMapNum
) {
673 return EFI_INVALID_PARAMETER
;
678 // Calculate graphics image data address in the image
680 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
684 // Calculate the BltBuffer needed size.
686 BltBufferSize
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
688 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
690 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
))) {
691 return EFI_UNSUPPORTED
;
693 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
696 if (*GopBlt
== NULL
) {
698 // GopBlt is not allocated by caller.
700 *GopBltSize
= (UINTN
) BltBufferSize
;
701 *GopBlt
= AllocatePool (*GopBltSize
);
703 if (*GopBlt
== NULL
) {
704 return EFI_OUT_OF_RESOURCES
;
708 // GopBlt has been allocated by caller.
710 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
711 *GopBltSize
= (UINTN
) BltBufferSize
;
712 return EFI_BUFFER_TOO_SMALL
;
716 *PixelWidth
= BmpHeader
->PixelWidth
;
717 *PixelHeight
= BmpHeader
->PixelHeight
;
720 // Convert image from BMP to Blt buffer format
723 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
724 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
725 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
726 switch (BmpHeader
->BitPerPixel
) {
729 // Convert 1-bit (2 colors) BMP to 24-bit color
731 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
732 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
733 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
734 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
745 // Convert 4-bit (16 colors) BMP Palette to 24-bit color
747 Index
= (*Image
) >> 4;
748 Blt
->Red
= BmpColorMap
[Index
].Red
;
749 Blt
->Green
= BmpColorMap
[Index
].Green
;
750 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
751 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
754 Index
= (*Image
) & 0x0f;
755 Blt
->Red
= BmpColorMap
[Index
].Red
;
756 Blt
->Green
= BmpColorMap
[Index
].Green
;
757 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
763 // Convert 8-bit (256 colors) BMP Palette to 24-bit color
765 Blt
->Red
= BmpColorMap
[*Image
].Red
;
766 Blt
->Green
= BmpColorMap
[*Image
].Green
;
767 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
774 Blt
->Blue
= *Image
++;
775 Blt
->Green
= *Image
++;
781 // Other bit format BMP is not supported.
787 return EFI_UNSUPPORTED
;
793 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
794 if ((ImageIndex
% 4) != 0) {
796 // Bmp Image starts each row on a 32-bit boundary!
798 Image
= Image
+ (4 - (ImageIndex
% 4));
806 Use SystemTable Conout to stop video based Simple Text Out consoles from going
807 to the video device. Put up LogoFile on every video device that is a console.
809 @param[in] LogoFile File name of logo to display on the center of the screen.
811 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
812 @retval EFI_UNSUPPORTED Logo not found
818 IN EFI_GUID
*LogoFile
822 EFI_OEM_BADGING_PROTOCOL
*Badging
;
831 EFI_BADGING_FORMAT Format
;
832 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
837 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
838 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
841 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
842 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
844 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*LogoBlt
;
857 // Try to open GOP first
859 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
860 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
861 GraphicsOutput
= NULL
;
863 // Open GOP failed, try to open UGA
865 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
867 if (EFI_ERROR (Status
)) {
868 return EFI_UNSUPPORTED
;
872 // Try to open Boot Logo Protocol.
875 gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
878 // Erase Cursor from screen
880 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
883 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
885 if (GraphicsOutput
!= NULL
) {
886 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
887 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
889 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
890 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
891 if (EFI_ERROR (Status
)) {
892 return EFI_UNSUPPORTED
;
895 return EFI_UNSUPPORTED
;
913 if (Badging
!= NULL
) {
915 // Get image from OEMBadging protocol.
917 Status
= Badging
->GetImage (
927 if (EFI_ERROR (Status
)) {
932 // Currently only support BMP format.
934 if (Format
!= EfiBadgingFormatBMP
) {
935 if (ImageData
!= NULL
) {
936 FreePool (ImageData
);
942 // Get the specified image from FV.
944 Status
= GetSectionFromAnyFv (LogoFile
, EFI_SECTION_RAW
, 0, (VOID
**) &ImageData
, &ImageSize
);
945 if (EFI_ERROR (Status
)) {
946 return EFI_UNSUPPORTED
;
951 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
952 Attribute
= EfiBadgingDisplayAttributeCenter
;
954 Attribute
= EfiBadgingDisplayAttributeCustomized
;
962 Status
= ConvertBmpToGopBlt (
970 if (EFI_ERROR (Status
)) {
971 FreePool (ImageData
);
973 if (Badging
== NULL
) {
981 // Calculate the display position according to Attribute.
984 case EfiBadgingDisplayAttributeLeftTop
:
989 case EfiBadgingDisplayAttributeCenterTop
:
990 DestX
= (SizeOfX
- Width
) / 2;
994 case EfiBadgingDisplayAttributeRightTop
:
995 DestX
= (SizeOfX
- Width
- CoordinateX
);
996 DestY
= CoordinateY
;;
999 case EfiBadgingDisplayAttributeCenterRight
:
1000 DestX
= (SizeOfX
- Width
- CoordinateX
);
1001 DestY
= (SizeOfY
- Height
) / 2;
1004 case EfiBadgingDisplayAttributeRightBottom
:
1005 DestX
= (SizeOfX
- Width
- CoordinateX
);
1006 DestY
= (SizeOfY
- Height
- CoordinateY
);
1009 case EfiBadgingDisplayAttributeCenterBottom
:
1010 DestX
= (SizeOfX
- Width
) / 2;
1011 DestY
= (SizeOfY
- Height
- CoordinateY
);
1014 case EfiBadgingDisplayAttributeLeftBottom
:
1015 DestX
= CoordinateX
;
1016 DestY
= (SizeOfY
- Height
- CoordinateY
);
1019 case EfiBadgingDisplayAttributeCenterLeft
:
1020 DestX
= CoordinateX
;
1021 DestY
= (SizeOfY
- Height
) / 2;
1024 case EfiBadgingDisplayAttributeCenter
:
1025 DestX
= (SizeOfX
- Width
) / 2;
1026 DestY
= (SizeOfY
- Height
) / 2;
1029 case EfiBadgingDisplayAttributeCustomized
:
1030 DestX
= (SizeOfX
- Width
) / 2;
1031 DestY
= ((SizeOfY
* 382) / 1000) - Height
/ 2;
1035 DestX
= CoordinateX
;
1036 DestY
= CoordinateY
;
1040 if ((DestX
>= 0) && (DestY
>= 0)) {
1041 if (GraphicsOutput
!= NULL
) {
1042 Status
= GraphicsOutput
->Blt (
1045 EfiBltBufferToVideo
,
1052 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1054 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
1055 Status
= UgaDraw
->Blt (
1057 (EFI_UGA_PIXEL
*) Blt
,
1058 EfiUgaBltBufferToVideo
,
1065 Width
* sizeof (EFI_UGA_PIXEL
)
1068 Status
= EFI_UNSUPPORTED
;
1072 // Report displayed Logo information.
1074 if (!EFI_ERROR (Status
)) {
1077 if (LogoWidth
== 0) {
1081 LogoDestX
= (UINTN
) DestX
;
1082 LogoDestY
= (UINTN
) DestY
;
1084 LogoHeight
= Height
;
1087 // Merge new logo with old one.
1089 NewDestX
= MIN ((UINTN
) DestX
, LogoDestX
);
1090 NewDestY
= MIN ((UINTN
) DestY
, LogoDestY
);
1091 NewWidth
= MAX ((UINTN
) DestX
+ Width
, LogoDestX
+ LogoWidth
) - NewDestX
;
1092 NewHeight
= MAX ((UINTN
) DestY
+ Height
, LogoDestY
+ LogoHeight
) - NewDestY
;
1094 LogoDestX
= NewDestX
;
1095 LogoDestY
= NewDestY
;
1096 LogoWidth
= NewWidth
;
1097 LogoHeight
= NewHeight
;
1102 FreePool (ImageData
);
1104 if (Badging
== NULL
) {
1110 if (BootLogo
== NULL
|| NumberOfLogos
== 0) {
1112 // No logo displayed.
1122 // Advertise displayed Logo information.
1124 if (NumberOfLogos
== 1) {
1126 // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.
1129 Status
= EFI_SUCCESS
;
1132 // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation.
1139 // Ensure the LogoHeight * LogoWidth doesn't overflow
1141 if (LogoHeight
> DivU64x64Remainder ((UINTN
) ~0, LogoWidth
, NULL
)) {
1142 return EFI_UNSUPPORTED
;
1144 BufferSize
= MultU64x64 (LogoWidth
, LogoHeight
);
1147 // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
1149 if (BufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
))) {
1150 return EFI_UNSUPPORTED
;
1153 LogoBlt
= AllocateZeroPool ((UINTN
)BufferSize
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1154 if (LogoBlt
== NULL
) {
1155 return EFI_OUT_OF_RESOURCES
;
1158 if (GraphicsOutput
!= NULL
) {
1159 Status
= GraphicsOutput
->Blt (
1162 EfiBltVideoToBltBuffer
,
1169 LogoWidth
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1171 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
1172 Status
= UgaDraw
->Blt (
1174 (EFI_UGA_PIXEL
*) LogoBlt
,
1175 EfiUgaVideoToBltBuffer
,
1182 LogoWidth
* sizeof (EFI_UGA_PIXEL
)
1185 Status
= EFI_UNSUPPORTED
;
1189 if (!EFI_ERROR (Status
)) {
1190 BootLogo
->SetBootLogo (BootLogo
, LogoBlt
, LogoDestX
, LogoDestY
, LogoWidth
, LogoHeight
);
1198 Use SystemTable Conout to turn on video based Simple Text Out consoles. The
1199 Simple Text Out screens will now be synced up with all non video output devices
1201 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
1212 // Enable Cursor on Screen
1214 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);