EFI_STATUS DisableQuietBoot ( VOID ) /*++ Routine Description: Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA Simple Text Out screens will now be synced up with all non GOP/UGA output devices Arguments: NONE Returns: EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up. EFI_UNSUPPORTED - Logo not found --*/ { EFI_STATUS Status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText); }
EFI_STATUS LockKeyboards ( IN CHAR16 *Password ) /*++ Routine Description: Use Console Control Protocol to lock the Console In Spliter virtual handle. This is the ConInHandle and ConIn handle in the EFI system table. All key presses will be ignored until the Password is typed in. The only way to disable the password is to type it in to a ConIn device. Arguments: Password - Password used to lock ConIn device Returns: EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo displayed. EFI_UNSUPPORTED - Logo not found --*/ { EFI_STATUS Status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } Status = ConsoleControl->LockStdIn (ConsoleControl, Password); return Status; }
void splash() { EFI_CONSOLE_CONTROL_PROTOCOL *cc; UINTN col = 0, row = 0; ST->ConOut->ClearScreen(ST->ConOut); if (EFI_SUCCESS == BS->LocateProtocol(&EfiConsoleControlProtocolGuid, NULL, (void *)&cc)) { int cur_mode = 0; cc->GetMode(cc, &cur_mode, NULL, NULL); if (cur_mode == 1) cc->SetMode(cc, 0); } if (EFI_SUCCESS == ST->ConOut->QueryMode(ST->ConOut, 2, &col, &row)) { if (EFI_SUCCESS != ST->ConOut->SetMode(ST->ConOut, 2)) { col = 0; row = 0; } } if (0 == col || 0 == row) { if (EFI_SUCCESS == ST->ConOut->QueryMode(ST->ConOut, 1, &col, &row)) { if (EFI_SUCCESS != ST->ConOut->SetMode(ST->ConOut, 1)) { col = 0; row = 0; } } } if (0 == col || 0 == row) { ST->ConOut->SetMode(ST->ConOut, 0); col = 80; row = 25; } ST->ConOut->EnableCursor(ST->ConOut, 0); int st = (col / 2) - 40; ST->ConOut->SetAttribute(ST->ConOut, SPLASH_LOGO_COLOR); for (int ln = 0; ln < SPLASH_LOGO_LINES; ln++) { if (SPLASH_LOGO_LINES == ln + 1) ST->ConOut->SetAttribute(ST->ConOut, SPLASH_URL_COLOR); ST->ConOut->SetCursorPosition(ST->ConOut, st, SPLASH_TOP + ln); ST->ConOut->OutputString(ST->ConOut, splash_logo[ln]); } ST->ConOut->SetAttribute(ST->ConOut, EFI_WHITE); }
VOID SwitchToText( IN BOOLEAN Force) { EFI_CONSOLE_CONTROL_SCREEN_MODE CurrentMode; EFI_STATUS Status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; Status = gBS->LocateProtocol(&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl); if (EFI_ERROR(Status)) { ConsoleControl = NULL; } if (ConsoleControl != NULL) { Status = ConsoleControl->GetMode(ConsoleControl, &CurrentMode, NULL, NULL); if (Force || (!EFI_ERROR(Status) && CurrentMode != EfiConsoleControlScreenText)) { ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); } } }
EFI_STATUS EFIAPI EBounceMain (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { EFI_STATUS Status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; EFI_CONSOLE_CONTROL_SCREEN_MODE currentMode; EFI_LOADED_IMAGE *SelfLoadedImage; EFI_FILE *RootDir; EFI_FILE *BootFile; EFI_DEVICE_PATH *DevicePath; CHAR16 *DevicePathAsString; CHAR16 DirName[256]; CHAR16 FileName[256]; UINTN i, FileNameIndex; EFI_HANDLE LoaderHandle; InitializeLib(ImageHandle, SystemTable); // switch to text mode if (BS->LocateProtocol(&gEfiConsoleControlProtocolGuid, NULL, &ConsoleControl) == EFI_SUCCESS) { ConsoleControl->GetMode(ConsoleControl, ¤tMode, NULL, NULL); if (currentMode == EfiConsoleControlScreenGraphics) ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); } /// load elilo.efi or e.efi from the same directory // get loaded image protocol for ourselves if (BS->HandleProtocol(ImageHandle, &LoadedImageProtocol, (VOID*)&SelfLoadedImage) != EFI_SUCCESS) { Print(L"Can not retrieve a LoadedImageProtocol handle for ImageHandle\n"); return EFI_NOT_FOUND; } // open volume RootDir = LibOpenRoot(SelfLoadedImage->DeviceHandle); if (RootDir == NULL) { Print(L"Can't open volume.\n"); return EFI_NOT_FOUND; } // find the current directory DevicePathAsString = DevicePathToStr(SelfLoadedImage->FilePath); if (DevicePathAsString != NULL) { StrCpy(DirName, DevicePathAsString); FreePool(DevicePathAsString); for (i = StrLen(DirName) - 1; i > 0 && DirName[i] != '\\'; i--) ; DirName[i++] = '\\'; DirName[i] = 0; } else { StrCpy(DirName, L"\\"); } for (FileNameIndex = 0; FileNames[FileNameIndex]; FileNameIndex++) { // build full absolute path name StrCpy(FileName, DirName); StrCat(FileName, FileNames[FileNameIndex]); // check for presence of the file if (RootDir->Open(RootDir, &BootFile, FileName, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS) continue; BootFile->Close(BootFile); // make a full device path for the image file DevicePath = FileDevicePath(SelfLoadedImage->DeviceHandle, FileName); // load the image into memory Status = BS->LoadImage(FALSE, ImageHandle, DevicePath, NULL, 0, &LoaderHandle); FreePool(DevicePath); if (EFI_ERROR(Status)) { Print(L"Can not load the file %s\n", FileName); return Status; } // start it! BS->StartImage(LoaderHandle, NULL, NULL); // just in case we get control back... break; } return EFI_SUCCESS; }
EFI_STATUS EnableQuietBootEx ( IN EFI_GUID *LogoFile, IN EFI_HANDLE ImageHandle ) /*++ Routine Description: Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console Arguments: LogoFile - File name of logo to display on the center of the screen. ImageHandle - The driver image handle of the caller. The parameter is used to optimize the loading of the logo file so that the FV from which the driver image is loaded will be tried first. Returns: EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo displayed. EFI_UNSUPPORTED - Logo not found --*/ { EFI_STATUS Status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; EFI_OEM_BADGING_PROTOCOL *Badging; UINT32 SizeOfX; UINT32 SizeOfY; INTN DestX; INTN DestY; UINT8 *ImageData; UINTN ImageSize; UINTN BltSize; UINT32 Instance; EFI_BADGING_FORMAT Format; EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; UINTN CoordinateX; UINTN CoordinateY; UINTN Height; UINTN Width; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; EFI_UGA_DRAW_PROTOCOL *UgaDraw; UINT32 ColorDepth; UINT32 RefreshRate; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } UgaDraw = NULL; // // Try to open GOP first // Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput); if (EFI_ERROR (Status)) { GraphicsOutput = NULL; // // Open GOP failed, try to open UGA // Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID**)&UgaDraw); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } } Badging = NULL; Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID**)&Badging); ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics); if (GraphicsOutput != NULL) { SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; } else { Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } } Instance = 0; while (1) { ImageData = NULL; ImageSize = 0; if (Badging != NULL) { Status = Badging->GetImage ( Badging, &Instance, &Format, &ImageData, &ImageSize, &Attribute, &CoordinateX, &CoordinateY ); if (EFI_ERROR (Status)) { return Status; } // // Currently only support BMP format // if (Format != EfiBadgingFormatBMP) { gBS->FreePool (ImageData); continue; } } else { Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, (VOID **) &ImageData, &ImageSize); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } CoordinateX = 0; CoordinateY = 0; Attribute = EfiBadgingDisplayAttributeCenter; } Blt = NULL; Status = ConvertBmpToGopBlt ( ImageData, ImageSize, (VOID**)&Blt, &BltSize, &Height, &Width ); if (EFI_ERROR (Status)) { gBS->FreePool (ImageData); if (Badging == NULL) { return Status; } else { continue; } } switch (Attribute) { case EfiBadgingDisplayAttributeLeftTop: DestX = CoordinateX; DestY = CoordinateY; break; case EfiBadgingDisplayAttributeCenterTop: DestX = (SizeOfX - Width) / 2; DestY = CoordinateY; break; case EfiBadgingDisplayAttributeRightTop: DestX = (SizeOfX - Width - CoordinateX); DestY = CoordinateY;; break; case EfiBadgingDisplayAttributeCenterRight: DestX = (SizeOfX - Width - CoordinateX); DestY = (SizeOfY - Height) / 2; break; case EfiBadgingDisplayAttributeRightBottom: DestX = (SizeOfX - Width - CoordinateX); DestY = (SizeOfY - Height - CoordinateY); break; case EfiBadgingDisplayAttributeCenterBottom: DestX = (SizeOfX - Width) / 2; DestY = (SizeOfY - Height - CoordinateY); break; case EfiBadgingDisplayAttributeLeftBottom: DestX = CoordinateX; DestY = (SizeOfY - Height - CoordinateY); break; case EfiBadgingDisplayAttributeCenterLeft: DestX = CoordinateX; DestY = (SizeOfY - Height) / 2; break; case EfiBadgingDisplayAttributeCenter: DestX = (SizeOfX - Width) / 2; DestY = (SizeOfY - Height) / 2; break; default: DestX = CoordinateX; DestY = CoordinateY; break; } if ((DestX >= 0) && (DestY >= 0)) { if (GraphicsOutput != NULL) { Status = GraphicsOutput->Blt ( GraphicsOutput, Blt, EfiBltBufferToVideo, 0, 0, (UINTN) DestX, (UINTN) DestY, Width, Height, Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) ); } else { Status = UgaDraw->Blt ( UgaDraw, (EFI_UGA_PIXEL *) Blt, EfiUgaBltBufferToVideo, 0, 0, (UINTN) DestX, (UINTN) DestY, Width, Height, Width * sizeof (EFI_UGA_PIXEL) ); } } gBS->FreePool (ImageData); gBS->FreePool (Blt); if (Badging == NULL) { break; } } return Status; }
EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab) { EFI_HANDLE handles[128]; EFI_BLOCK_IO *blkio; UINTN i, nparts = sizeof(handles), cols, rows, max_dim, best_mode; EFI_STATUS status; EFI_DEVICE_PATH *devpath; EFI_BOOT_SERVICES *BS; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL; const char *path = _PATH_LOADER; systab = Xsystab; image = Ximage; BS = systab->BootServices; status = BS->LocateProtocol(&ConsoleControlGUID, NULL, (VOID **)&ConsoleControl); if (status == EFI_SUCCESS) (void)ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); /* * Reset the console and find the best text mode. */ conout = systab->ConOut; conout->Reset(conout, TRUE); max_dim = best_mode = 0; for (i = 0; ; i++) { status = conout->QueryMode(conout, i, &cols, &rows); if (EFI_ERROR(status)) break; if (cols * rows > max_dim) { max_dim = cols * rows; best_mode = i; } } if (max_dim > 0) conout->SetMode(conout, best_mode); conout->EnableCursor(conout, TRUE); conout->ClearScreen(conout); printf("\n" ">> FreeBSD EFI boot block\n"); printf(" Loader path: %s\n", path); status = systab->BootServices->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL, &nparts, handles); nparts /= sizeof(handles[0]); for (i = 0; i < nparts; i++) { status = systab->BootServices->HandleProtocol(handles[i], &DevicePathGUID, (void **)&devpath); if (EFI_ERROR(status)) continue; while (!IsDevicePathEnd(NextDevicePathNode(devpath))) devpath = NextDevicePathNode(devpath); status = systab->BootServices->HandleProtocol(handles[i], &BlockIoProtocolGUID, (void **)&blkio); if (EFI_ERROR(status)) continue; if (!blkio->Media->LogicalPartition) continue; if (domount(devpath, blkio, 1) >= 0) break; } if (i == nparts) panic("No bootable partition found"); bootdevhandle = handles[i]; load(path); panic("Load failed"); return EFI_SUCCESS; }