2 BDS Lib functions which contain all the code to connect console device
4 Copyright (c) 2004 - 2013, 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
;
91 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*TextOut
;
93 ASSERT (VarName
!= NULL
);
94 ASSERT (ConsoleHandle
!= NULL
);
95 ASSERT (ConsoleGuid
!= NULL
);
96 ASSERT (ProtocolInterface
!= NULL
);
98 if (*ConsoleHandle
!= NULL
) {
99 Status
= gBS
->HandleProtocol (
104 if (Status
== EFI_SUCCESS
&& Interface
== *ProtocolInterface
) {
106 // If ConsoleHandle is valid and console protocol on this handle also
107 // also matched, just return.
114 // Get all possible consoles device path from EFI variable
116 VarConsole
= BdsLibGetVariableAndSize (
118 &gEfiGlobalVariableGuid
,
121 if (VarConsole
== NULL
) {
123 // If there is no any console device, just return.
128 FullDevicePath
= VarConsole
;
132 // Check every instance of the console variable
134 Instance
= GetNextDevicePathInstance (&VarConsole
, &DevicePathSize
);
135 if (Instance
== NULL
) {
136 FreePool (FullDevicePath
);
141 // Find console device handle by device path instance
143 Status
= gBS
->LocateDevicePath (
148 if (!EFI_ERROR (Status
)) {
150 // Get the console protocol on this console device handle
152 Status
= gBS
->HandleProtocol (
157 if (!EFI_ERROR (Status
)) {
159 // Update new console handle in System Table.
161 *ConsoleHandle
= NewHandle
;
162 *ProtocolInterface
= Interface
;
163 if (CompareGuid (ConsoleGuid
, &gEfiSimpleTextOutProtocolGuid
)) {
165 // If it is console out device, set console mode 80x25 if current mode is invalid.
167 TextOut
= (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*) Interface
;
168 if (TextOut
->Mode
->Mode
== -1) {
169 TextOut
->SetMode (TextOut
, 0);
176 } while (Instance
!= NULL
);
179 // No any available console devcie found.
185 Connect the console device base on the variable ConVarName, if
186 device path of the ConVarName is multi-instance device path and
187 anyone of the instances is connected success, this function will
189 Dispatch service is called basing on input when the handle associate
190 with one device path node can not be created successfully. Since in
191 some cases we assume driver dependency does not exist and do not
192 need to call this service.
194 @param ConVarName Console related variable name, ConIn, ConOut,
196 @param NeedDispatch Whether requires dispatch service during connection
198 @retval EFI_NOT_FOUND There is not any console devices connected
200 @retval EFI_SUCCESS Success connect any one instance of the console
201 device path base on the variable ConVarName.
205 ConnectConsoleVariableInternal (
206 IN CHAR16
*ConVarName
,
207 IN BOOLEAN NeedDispatch
211 EFI_DEVICE_PATH_PROTOCOL
*StartDevicePath
;
213 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
214 EFI_DEVICE_PATH_PROTOCOL
*Next
;
215 EFI_DEVICE_PATH_PROTOCOL
*CopyOfDevicePath
;
219 Status
= EFI_SUCCESS
;
223 // Check if the console variable exist
225 StartDevicePath
= BdsLibGetVariableAndSize (
227 &gEfiGlobalVariableGuid
,
230 if (StartDevicePath
== NULL
) {
231 return EFI_UNSUPPORTED
;
234 CopyOfDevicePath
= StartDevicePath
;
237 // Check every instance of the console variable
239 Instance
= GetNextDevicePathInstance (&CopyOfDevicePath
, &Size
);
240 if (Instance
== NULL
) {
241 FreePool (StartDevicePath
);
242 return EFI_UNSUPPORTED
;
246 while (!IsDevicePathEndType (Next
)) {
247 Next
= NextDevicePathNode (Next
);
250 SetDevicePathEndNode (Next
);
252 // Connect the USB console
253 // USB console device path is a short-form device path that
254 // starts with the first element being a USB WWID
255 // or a USB Class device path
257 if ((DevicePathType (Instance
) == MESSAGING_DEVICE_PATH
) &&
258 ((DevicePathSubType (Instance
) == MSG_USB_CLASS_DP
)
259 || (DevicePathSubType (Instance
) == MSG_USB_WWID_DP
)
261 Status
= BdsLibConnectUsbDevByShortFormDP (0xFF, Instance
);
262 if (!EFI_ERROR (Status
)) {
267 // Connect the instance device path
269 Status
= ConnectDevicePathInternal (Instance
, NeedDispatch
);
271 if (EFI_ERROR (Status
)) {
273 // Delete the instance from the console varialbe
275 BdsLibUpdateConsoleVariable (ConVarName
, NULL
, Instance
);
281 } while (CopyOfDevicePath
!= NULL
);
283 FreePool (StartDevicePath
);
286 return EFI_NOT_FOUND
;
293 This function update console variable based on ConVarName, it can
294 add or remove one specific console device path from the variable
296 @param ConVarName Console related variable name, ConIn, ConOut,
298 @param CustomizedConDevicePath The console device path which will be added to
299 the console variable ConVarName, this parameter
300 can not be multi-instance.
301 @param ExclusiveDevicePath The console device path which will be removed
302 from the console variable ConVarName, this
303 parameter can not be multi-instance.
305 @retval EFI_UNSUPPORTED The added device path is same to the removed one.
306 @retval EFI_SUCCESS Success add or remove the device path from the
312 BdsLibUpdateConsoleVariable (
313 IN CHAR16
*ConVarName
,
314 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
315 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
319 EFI_DEVICE_PATH_PROTOCOL
*VarConsole
;
320 UINTN DevicePathSize
;
321 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
322 EFI_DEVICE_PATH_PROTOCOL
*TempNewDevicePath
;
329 // Notes: check the device path point, here should check
330 // with compare memory
332 if (CustomizedConDevicePath
== ExclusiveDevicePath
) {
333 return EFI_UNSUPPORTED
;
336 // Delete the ExclusiveDevicePath from current default console
338 VarConsole
= BdsLibGetVariableAndSize (
340 &gEfiGlobalVariableGuid
,
345 // Initialize NewDevicePath
347 NewDevicePath
= VarConsole
;
350 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
351 // In the end, NewDevicePath is the final device path.
353 if (ExclusiveDevicePath
!= NULL
&& VarConsole
!= NULL
) {
354 NewDevicePath
= BdsLibDelPartMatchInstance (VarConsole
, ExclusiveDevicePath
);
357 // Try to append customized device path to NewDevicePath.
359 if (CustomizedConDevicePath
!= NULL
) {
360 if (!BdsLibMatchDevicePaths (NewDevicePath
, CustomizedConDevicePath
)) {
362 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
364 NewDevicePath
= BdsLibDelPartMatchInstance (NewDevicePath
, CustomizedConDevicePath
);
366 // In the first check, the default console variable will be _ModuleEntryPoint,
367 // just append current customized device path
369 TempNewDevicePath
= NewDevicePath
;
370 NewDevicePath
= AppendDevicePathInstance (NewDevicePath
, CustomizedConDevicePath
);
371 if (TempNewDevicePath
!= NULL
) {
372 FreePool(TempNewDevicePath
);
378 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
380 if (IsNvNeed(ConVarName
)) {
382 // ConVarName has NV attribute.
384 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
;
387 // ConVarName does not have NV attribute.
389 Attributes
= EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
393 // Finally, Update the variable of the default console by NewDevicePath
395 DevicePathSize
= GetDevicePathSize (NewDevicePath
);
396 Status
= gRT
->SetVariable (
398 &gEfiGlobalVariableGuid
,
403 if ((DevicePathSize
== 0) && (Status
== EFI_NOT_FOUND
)) {
404 Status
= EFI_SUCCESS
;
406 ASSERT_EFI_ERROR (Status
);
408 if (VarConsole
== NewDevicePath
) {
409 if (VarConsole
!= NULL
) {
410 FreePool(VarConsole
);
413 if (VarConsole
!= NULL
) {
414 FreePool(VarConsole
);
416 if (NewDevicePath
!= NULL
) {
417 FreePool(NewDevicePath
);
427 Connect the console device base on the variable ConVarName, if
428 device path of the ConVarName is multi-instance device path and
429 anyone of the instances is connected success, then this function
431 If the handle associate with one device path node can not
432 be created successfully, then still give chance to do the dispatch,
433 which load the missing drivers if possible..
435 @param ConVarName Console related variable name, ConIn, ConOut,
438 @retval EFI_NOT_FOUND There is not any console devices connected
440 @retval EFI_SUCCESS Success connect any one instance of the console
441 device path base on the variable ConVarName.
446 BdsLibConnectConsoleVariable (
447 IN CHAR16
*ConVarName
450 return ConnectConsoleVariableInternal(ConVarName
, TRUE
);
454 Connect the console device base on the variable ConVarName, if
455 device path of the ConVarName is multi-instance device path and
456 anyone of the instances is connected success, then this function
458 Dispatch service is not called when the handle associate with one
459 device path node can not be created successfully. Here no driver
460 dependency is assumed exist, so need not to call this service.
463 @param ConVarName Console related variable name, ConIn, ConOut,
466 @retval EFI_NOT_FOUND There is not any console devices connected
468 @retval EFI_SUCCESS Success connect any one instance of the console
469 device path base on the variable ConVarName.
474 BdsLibConnectConsoleVariableWithOutDispatch (
475 IN CHAR16
*ConVarName
478 return ConnectConsoleVariableInternal(ConVarName
, FALSE
);
482 This function will search every simpletext device in current system,
483 and make every simpletext device as pertantial console device.
488 BdsLibConnectAllConsoles (
493 EFI_DEVICE_PATH_PROTOCOL
*ConDevicePath
;
495 EFI_HANDLE
*HandleBuffer
;
500 ConDevicePath
= NULL
;
503 // Update all the console variables
505 gBS
->LocateHandleBuffer (
507 &gEfiSimpleTextInProtocolGuid
,
513 for (Index
= 0; Index
< HandleCount
; Index
++) {
514 gBS
->HandleProtocol (
516 &gEfiDevicePathProtocolGuid
,
517 (VOID
**) &ConDevicePath
519 BdsLibUpdateConsoleVariable (L
"ConIn", ConDevicePath
, NULL
);
522 if (HandleBuffer
!= NULL
) {
523 FreePool(HandleBuffer
);
527 gBS
->LocateHandleBuffer (
529 &gEfiSimpleTextOutProtocolGuid
,
534 for (Index
= 0; Index
< HandleCount
; Index
++) {
535 gBS
->HandleProtocol (
537 &gEfiDevicePathProtocolGuid
,
538 (VOID
**) &ConDevicePath
540 BdsLibUpdateConsoleVariable (L
"ConOut", ConDevicePath
, NULL
);
541 BdsLibUpdateConsoleVariable (L
"ErrOut", ConDevicePath
, NULL
);
544 if (HandleBuffer
!= NULL
) {
545 FreePool(HandleBuffer
);
549 // Connect all console variables
551 BdsLibConnectAllDefaultConsoles ();
556 This function will connect console device base on the console
557 device variable ConIn, ConOut and ErrOut.
559 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
560 been connected success.
561 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
566 BdsLibConnectAllDefaultConsoles (
571 BOOLEAN SystemTableUpdated
;
574 // Connect all default console variables
578 // It seems impossible not to have any ConOut device on platform,
579 // so we check the status here.
581 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
582 if (EFI_ERROR (Status
)) {
587 // Insert the performance probe for Console Out
589 PERF_START (NULL
, "ConOut", "BDS", 1);
590 PERF_END (NULL
, "ConOut", "BDS", 0);
593 // Because possibly the platform is legacy free, in such case,
594 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
595 // so we need not check the status.
597 BdsLibConnectConsoleVariable (L
"ConIn");
600 // The _ModuleEntryPoint err out var is legal.
602 BdsLibConnectConsoleVariable (L
"ErrOut");
604 SystemTableUpdated
= FALSE
;
606 // Fill console handles in System Table if no console device assignd.
608 if (UpdateSystemTableConsole (L
"ConIn", &gEfiSimpleTextInProtocolGuid
, &gST
->ConsoleInHandle
, (VOID
**) &gST
->ConIn
)) {
609 SystemTableUpdated
= TRUE
;
611 if (UpdateSystemTableConsole (L
"ConOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->ConsoleOutHandle
, (VOID
**) &gST
->ConOut
)) {
612 SystemTableUpdated
= TRUE
;
614 if (UpdateSystemTableConsole (L
"ErrOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->StandardErrorHandle
, (VOID
**) &gST
->StdErr
)) {
615 SystemTableUpdated
= TRUE
;
618 if (SystemTableUpdated
) {
620 // Update the CRC32 in the EFI System Table header
623 gBS
->CalculateCrc32 (
635 This function will connect console device except ConIn base on the console
636 device variable ConOut and ErrOut.
638 @retval EFI_SUCCESS At least one of the ConOut device have
639 been connected success.
640 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
645 BdsLibConnectAllDefaultConsolesWithOutConIn (
650 BOOLEAN SystemTableUpdated
;
653 // Connect all default console variables except ConIn
657 // It seems impossible not to have any ConOut device on platform,
658 // so we check the status here.
660 Status
= BdsLibConnectConsoleVariable (L
"ConOut");
661 if (EFI_ERROR (Status
)) {
666 // Insert the performance probe for Console Out
668 PERF_START (NULL
, "ConOut", "BDS", 1);
669 PERF_END (NULL
, "ConOut", "BDS", 0);
672 // The _ModuleEntryPoint err out var is legal.
674 BdsLibConnectConsoleVariable (L
"ErrOut");
676 SystemTableUpdated
= FALSE
;
678 // Fill console handles in System Table if no console device assignd.
680 if (UpdateSystemTableConsole (L
"ConOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->ConsoleOutHandle
, (VOID
**) &gST
->ConOut
)) {
681 SystemTableUpdated
= TRUE
;
683 if (UpdateSystemTableConsole (L
"ErrOut", &gEfiSimpleTextOutProtocolGuid
, &gST
->StandardErrorHandle
, (VOID
**) &gST
->StdErr
)) {
684 SystemTableUpdated
= TRUE
;
687 if (SystemTableUpdated
) {
689 // Update the CRC32 in the EFI System Table header
692 gBS
->CalculateCrc32 (
704 Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
705 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
706 buffer is passed in it will be used if it is big enough.
708 @param BmpImage Pointer to BMP file
709 @param BmpImageSize Number of bytes in BmpImage
710 @param GopBlt Buffer containing GOP version of BmpImage.
711 @param GopBltSize Size of GopBlt in bytes.
712 @param PixelHeight Height of GopBlt/BmpImage in pixels
713 @param PixelWidth Width of GopBlt/BmpImage in pixels
715 @retval EFI_SUCCESS GopBlt and GopBltSize are returned.
716 @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
717 @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
718 GopBltSize will contain the required size.
719 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
725 IN UINTN BmpImageSize
,
726 IN OUT VOID
**GopBlt
,
727 IN OUT UINTN
*GopBltSize
,
728 OUT UINTN
*PixelHeight
,
729 OUT UINTN
*PixelWidth
734 BMP_IMAGE_HEADER
*BmpHeader
;
735 BMP_COLOR_MAP
*BmpColorMap
;
736 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
737 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
738 UINT64 BltBufferSize
;
743 UINT32 DataSizePerLine
;
747 if (sizeof (BMP_IMAGE_HEADER
) > BmpImageSize
) {
748 return EFI_INVALID_PARAMETER
;
751 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
753 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
754 return EFI_UNSUPPORTED
;
758 // Doesn't support compress.
760 if (BmpHeader
->CompressionType
!= 0) {
761 return EFI_UNSUPPORTED
;
765 // Only support BITMAPINFOHEADER format.
766 // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER
768 if (BmpHeader
->HeaderSize
!= sizeof (BMP_IMAGE_HEADER
) - OFFSET_OF(BMP_IMAGE_HEADER
, HeaderSize
)) {
769 return EFI_UNSUPPORTED
;
773 // The data size in each line must be 4 byte alignment.
775 DataSizePerLine
= ((BmpHeader
->PixelWidth
* BmpHeader
->BitPerPixel
+ 31) >> 3) & (~0x3);
776 BltBufferSize
= MultU64x32 (DataSizePerLine
, BmpHeader
->PixelHeight
);
777 if (BltBufferSize
> (UINT32
) ~0) {
778 return EFI_INVALID_PARAMETER
;
781 if ((BmpHeader
->Size
!= BmpImageSize
) ||
782 (BmpHeader
->Size
< BmpHeader
->ImageOffset
) ||
783 (BmpHeader
->Size
- BmpHeader
->ImageOffset
!= BmpHeader
->PixelHeight
* DataSizePerLine
)) {
784 return EFI_INVALID_PARAMETER
;
788 // Calculate Color Map offset in the image.
791 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
792 if (BmpHeader
->ImageOffset
< sizeof (BMP_IMAGE_HEADER
)) {
793 return EFI_INVALID_PARAMETER
;
796 if (BmpHeader
->ImageOffset
> sizeof (BMP_IMAGE_HEADER
)) {
797 switch (BmpHeader
->BitPerPixel
) {
812 // BMP file may has padding data between the bmp header section and the bmp data section.
814 if (BmpHeader
->ImageOffset
- sizeof (BMP_IMAGE_HEADER
) < sizeof (BMP_COLOR_MAP
) * ColorMapNum
) {
815 return EFI_INVALID_PARAMETER
;
820 // Calculate graphics image data address in the image
822 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
826 // Calculate the BltBuffer needed size.
828 BltBufferSize
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
830 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
832 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
))) {
833 return EFI_UNSUPPORTED
;
835 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
838 if (*GopBlt
== NULL
) {
840 // GopBlt is not allocated by caller.
842 *GopBltSize
= (UINTN
) BltBufferSize
;
843 *GopBlt
= AllocatePool (*GopBltSize
);
845 if (*GopBlt
== NULL
) {
846 return EFI_OUT_OF_RESOURCES
;
850 // GopBlt has been allocated by caller.
852 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
853 *GopBltSize
= (UINTN
) BltBufferSize
;
854 return EFI_BUFFER_TOO_SMALL
;
858 *PixelWidth
= BmpHeader
->PixelWidth
;
859 *PixelHeight
= BmpHeader
->PixelHeight
;
862 // Convert image from BMP to Blt buffer format
865 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
866 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
867 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
868 switch (BmpHeader
->BitPerPixel
) {
871 // Convert 1-bit (2 colors) BMP to 24-bit color
873 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
874 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
875 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
876 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
887 // Convert 4-bit (16 colors) BMP Palette to 24-bit color
889 Index
= (*Image
) >> 4;
890 Blt
->Red
= BmpColorMap
[Index
].Red
;
891 Blt
->Green
= BmpColorMap
[Index
].Green
;
892 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
893 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
896 Index
= (*Image
) & 0x0f;
897 Blt
->Red
= BmpColorMap
[Index
].Red
;
898 Blt
->Green
= BmpColorMap
[Index
].Green
;
899 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
905 // Convert 8-bit (256 colors) BMP Palette to 24-bit color
907 Blt
->Red
= BmpColorMap
[*Image
].Red
;
908 Blt
->Green
= BmpColorMap
[*Image
].Green
;
909 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
916 Blt
->Blue
= *Image
++;
917 Blt
->Green
= *Image
++;
923 // Other bit format BMP is not supported.
929 return EFI_UNSUPPORTED
;
935 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
936 if ((ImageIndex
% 4) != 0) {
938 // Bmp Image starts each row on a 32-bit boundary!
940 Image
= Image
+ (4 - (ImageIndex
% 4));
948 Use SystemTable Conout to stop video based Simple Text Out consoles from going
949 to the video device. Put up LogoFile on every video device that is a console.
951 @param[in] LogoFile File name of logo to display on the center of the screen.
953 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
954 @retval EFI_UNSUPPORTED Logo not found
960 IN EFI_GUID
*LogoFile
964 EFI_OEM_BADGING_PROTOCOL
*Badging
;
973 EFI_BADGING_FORMAT Format
;
974 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
979 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
980 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
983 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
984 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
986 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*LogoBlt
;
999 // Try to open GOP first
1001 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
1002 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
1003 GraphicsOutput
= NULL
;
1005 // Open GOP failed, try to open UGA
1007 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
1009 if (EFI_ERROR (Status
)) {
1010 return EFI_UNSUPPORTED
;
1014 // Try to open Boot Logo Protocol.
1017 gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1020 // Erase Cursor from screen
1022 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1025 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
1027 if (GraphicsOutput
!= NULL
) {
1028 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1029 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1031 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
1032 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
1033 if (EFI_ERROR (Status
)) {
1034 return EFI_UNSUPPORTED
;
1037 return EFI_UNSUPPORTED
;
1055 if (Badging
!= NULL
) {
1057 // Get image from OEMBadging protocol.
1059 Status
= Badging
->GetImage (
1069 if (EFI_ERROR (Status
)) {
1074 // Currently only support BMP format.
1076 if (Format
!= EfiBadgingFormatBMP
) {
1077 if (ImageData
!= NULL
) {
1078 FreePool (ImageData
);
1084 // Get the specified image from FV.
1086 Status
= GetSectionFromAnyFv (LogoFile
, EFI_SECTION_RAW
, 0, (VOID
**) &ImageData
, &ImageSize
);
1087 if (EFI_ERROR (Status
)) {
1088 return EFI_UNSUPPORTED
;
1093 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
1094 Attribute
= EfiBadgingDisplayAttributeCenter
;
1096 Attribute
= EfiBadgingDisplayAttributeCustomized
;
1104 Status
= ConvertBmpToGopBlt (
1112 if (EFI_ERROR (Status
)) {
1113 FreePool (ImageData
);
1115 if (Badging
== NULL
) {
1123 // Calculate the display position according to Attribute.
1125 switch (Attribute
) {
1126 case EfiBadgingDisplayAttributeLeftTop
:
1127 DestX
= CoordinateX
;
1128 DestY
= CoordinateY
;
1131 case EfiBadgingDisplayAttributeCenterTop
:
1132 DestX
= (SizeOfX
- Width
) / 2;
1133 DestY
= CoordinateY
;
1136 case EfiBadgingDisplayAttributeRightTop
:
1137 DestX
= (SizeOfX
- Width
- CoordinateX
);
1138 DestY
= CoordinateY
;;
1141 case EfiBadgingDisplayAttributeCenterRight
:
1142 DestX
= (SizeOfX
- Width
- CoordinateX
);
1143 DestY
= (SizeOfY
- Height
) / 2;
1146 case EfiBadgingDisplayAttributeRightBottom
:
1147 DestX
= (SizeOfX
- Width
- CoordinateX
);
1148 DestY
= (SizeOfY
- Height
- CoordinateY
);
1151 case EfiBadgingDisplayAttributeCenterBottom
:
1152 DestX
= (SizeOfX
- Width
) / 2;
1153 DestY
= (SizeOfY
- Height
- CoordinateY
);
1156 case EfiBadgingDisplayAttributeLeftBottom
:
1157 DestX
= CoordinateX
;
1158 DestY
= (SizeOfY
- Height
- CoordinateY
);
1161 case EfiBadgingDisplayAttributeCenterLeft
:
1162 DestX
= CoordinateX
;
1163 DestY
= (SizeOfY
- Height
) / 2;
1166 case EfiBadgingDisplayAttributeCenter
:
1167 DestX
= (SizeOfX
- Width
) / 2;
1168 DestY
= (SizeOfY
- Height
) / 2;
1171 case EfiBadgingDisplayAttributeCustomized
:
1172 DestX
= (SizeOfX
- Width
) / 2;
1173 DestY
= ((SizeOfY
* 382) / 1000) - Height
/ 2;
1177 DestX
= CoordinateX
;
1178 DestY
= CoordinateY
;
1182 if ((DestX
>= 0) && (DestY
>= 0)) {
1183 if (GraphicsOutput
!= NULL
) {
1184 Status
= GraphicsOutput
->Blt (
1187 EfiBltBufferToVideo
,
1194 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1196 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
1197 Status
= UgaDraw
->Blt (
1199 (EFI_UGA_PIXEL
*) Blt
,
1200 EfiUgaBltBufferToVideo
,
1207 Width
* sizeof (EFI_UGA_PIXEL
)
1210 Status
= EFI_UNSUPPORTED
;
1214 // Report displayed Logo information.
1216 if (!EFI_ERROR (Status
)) {
1219 if (LogoWidth
== 0) {
1223 LogoDestX
= (UINTN
) DestX
;
1224 LogoDestY
= (UINTN
) DestY
;
1226 LogoHeight
= Height
;
1229 // Merge new logo with old one.
1231 NewDestX
= MIN ((UINTN
) DestX
, LogoDestX
);
1232 NewDestY
= MIN ((UINTN
) DestY
, LogoDestY
);
1233 NewWidth
= MAX ((UINTN
) DestX
+ Width
, LogoDestX
+ LogoWidth
) - NewDestX
;
1234 NewHeight
= MAX ((UINTN
) DestY
+ Height
, LogoDestY
+ LogoHeight
) - NewDestY
;
1236 LogoDestX
= NewDestX
;
1237 LogoDestY
= NewDestY
;
1238 LogoWidth
= NewWidth
;
1239 LogoHeight
= NewHeight
;
1244 FreePool (ImageData
);
1246 if (Badging
== NULL
) {
1252 if (BootLogo
== NULL
|| NumberOfLogos
== 0) {
1254 // No logo displayed.
1264 // Advertise displayed Logo information.
1266 if (NumberOfLogos
== 1) {
1268 // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.
1271 Status
= EFI_SUCCESS
;
1274 // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation.
1281 // Ensure the LogoHeight * LogoWidth doesn't overflow
1283 if (LogoHeight
> DivU64x64Remainder ((UINTN
) ~0, LogoWidth
, NULL
)) {
1284 return EFI_UNSUPPORTED
;
1286 BufferSize
= MultU64x64 (LogoWidth
, LogoHeight
);
1289 // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
1291 if (BufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
))) {
1292 return EFI_UNSUPPORTED
;
1295 LogoBlt
= AllocateZeroPool ((UINTN
)BufferSize
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1296 if (LogoBlt
== NULL
) {
1297 return EFI_OUT_OF_RESOURCES
;
1300 if (GraphicsOutput
!= NULL
) {
1301 Status
= GraphicsOutput
->Blt (
1304 EfiBltVideoToBltBuffer
,
1311 LogoWidth
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1313 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
1314 Status
= UgaDraw
->Blt (
1316 (EFI_UGA_PIXEL
*) LogoBlt
,
1317 EfiUgaVideoToBltBuffer
,
1324 LogoWidth
* sizeof (EFI_UGA_PIXEL
)
1327 Status
= EFI_UNSUPPORTED
;
1331 if (!EFI_ERROR (Status
)) {
1332 BootLogo
->SetBootLogo (BootLogo
, LogoBlt
, LogoDestX
, LogoDestY
, LogoWidth
, LogoHeight
);
1340 Use SystemTable Conout to turn on video based Simple Text Out consoles. The
1341 Simple Text Out screens will now be synced up with all non video output devices
1343 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
1354 // Enable Cursor on Screen
1356 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);