c - 如何在 EFI 图形模式下使用文本?
问题描述
我对创建 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;
}
解决方案
UEFI 支持图形输出。它还支持文本输出(这可能意味着输出到串行控制台,或呈现到图形控制台的文本,或两者兼而有之)。但是没有明确的方式以受控方式在它们之间进行交互。
提供带有文本元素的图形环境(BIOS 配置菜单,GRUB)的应用程序通常使用它们自己的框架来执行此操作,以使用 GRAPHICS_OUTPUT_PROTOCOL 在图形控制台上绘制文本。
推荐阅读
- angular - Angular Material Sort Header 不会将空值排序到最后
- robotframework - 如何从列表中获取所有项目
- unix - 解析具有多行的文件并用管道替换每个第一次出现
- visual-studio - 使用执行 SQL 任务在 SSIS 中执行过程的问题
- java - 检查字符串数组然后将其写入文件的最有效方法
- php - 带有 ACF 中继器和 PHP reset_rows 的增量计数器
- javascript - 将十六进制 HTML 颜色存储为数值转换返回不同的颜色
- r - 如何根据 R 中的其他列复制行以将数据回填到某个日期?
- ruby - 尝试将我的密码详细信息解析为 yaml,而不是手动输入
- ruby-on-rails - 如何检查对象上的 nil?