【发布时间】:2019-09-25 11:18:24
【问题描述】:
我对创建 efi 应用程序非常陌生。我的目标是在 efi 中创建一个小型应用程序,在背景上显示一些文本。但我坚持尝试在显示器上显示文本(最好有一个自定义字体,但在这个阶段没有必要)。我希望应用程序(也)在苹果系统上运行(从 USB 启动)
如何找到有关 EFI 功能的良好文档?似乎很难找到好的例子等等。
如何使用 EFI 在背景上显示文本?
这是我到目前为止所得到的。我使用图形协议将背景更改为颜色。如何在其上显示文本。输出字符串似乎不起作用。
#include "efibind.h"
#include "efidef.h"
#include "efidevp.h"
#include "eficon.h"
#include "efiapi.h"
#include "efierr.h"
#include "efiprot.h"
static EFI_GUID GraphicsOutputProtocolGUID = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
/**
* efi_main - The entry point for the EFI application
* @image: firmware-allocated handle that identifies the image
* @SystemTable: EFI system table
*/
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable) {
EFI_BOOT_SERVICES *bs = systemTable->BootServices;
EFI_STATUS status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *graphicsProtocol;
SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN SizeOfInfo, sWidth, sHeight;
status = bs->LocateProtocol(&GraphicsOutputProtocolGUID, NULL,
(void**)&graphicsProtocol);
if (EFI_ERROR(status) || graphicsProtocol == NULL) {
conOut->OutputString(conOut, L"Failed to init gfx!\r\n");
return status;
}
conOut->ClearScreen(conOut);
//Switch to current mode so gfx is started.
status = graphicsProtocol->SetMode(graphicsProtocol, graphicsProtocol->Mode->Mode);
if (EFI_ERROR(status)) {
conOut->OutputString(conOut, L"Failed to set default mode!\r\n");
return status;
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL p;
p.Red = 200;
p.Green = 77;
p.Blue = 13;
graphicsProtocol->QueryMode(graphicsProtocol, graphicsProtocol->Mode->Mode, &SizeOfInfo, &info);
sWidth = info->HorizontalResolution;
sHeight = info->VerticalResolution;
status = graphicsProtocol->Blt(graphicsProtocol, &p, EfiBltVideoFill, 0, 0, 0, 0, sWidth, sHeight, 0);
while (1) {
conOut->OutputString(conOut, L"Some text that I want to display\r\n");
bs->Stall(500000);
}
return EFI_SUCCESS;
}
【问题讨论】:
-
您说的是 EFI (v1.x) 还是 UEFI (v2.x)?使用 EDK2 (UEFI) 构建时,您的代码可以正常工作。
-
@MiSimon 我都试过了,它可以在模拟器中运行,但不能从 Mac 上启动:/ 这就是问题所在!
-
您的系统上可能有多个 SIMPLE_TEXT_OUTPUT_INTERFACE 实例可用,使用 bs->LocateHandleBuffer 获取安装了 SIMPLE_TEXT_OUTPUT_INTERFACE 的所有可用句柄,并尝试在所有实例上调用 OutputString(使用 bs->OpenProtocol 获取句柄中的实例)。
-
所以我发现如果我只在 mac 上显示文本,我会看到它,但只是很快 - 就像一个快速闪烁然后我继续启动到 macos ......在 pc 上工作正常