UEFI Application là gì?
Quicknote giải thích UEFI Application.
UEFI Application là chương trình chạy trong môi trường UEFI, thường được load từ UEFI Shell, Boot Manager hoặc chain boot. Nó rất phù hợp để học UEFI vì ít phụ thuộc dispatcher/DEPEX hơn DXE driver.
Nếu bạn mới muốn thử GetVariable(), dump memory map, locate protocol hoặc đọc file từ ESP, UEFI Application thường là điểm bắt đầu dễ nhất.
Entry point tối giản
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
Print (L"Hello from UEFI app\n");
return EFI_SUCCESS;
}
INF tương ứng:
[Defines]
INF_VERSION = 0x00010017
BASE_NAME = MyApp
FILE_GUID = 55555555-6666-7777-8888-999999999999
MODULE_TYPE = UEFI_APPLICATION
ENTRY_POINT = UefiMain
[Sources]
MyApp.c
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
UefiBootServicesTableLib
Chạy từ UEFI Shell
ESP layout để test app
fs0:/
└─ EFI/
└─ Tools/
└─ MyApp.efi Trong shell:
Shell> fs0:
FS0:\> cd EFI\Tools
FS0:\EFI\Tools> MyApp.efi
Hello from UEFI app
Ứng dụng thực tế
UEFI Application rất hữu ích để viết tool nhỏ:
- dump
BootOrder,BootNext,BootCurrent; - gọi
GetVariable()để đọc NVRAM; - locate
SimpleFileSystemProtocolđể đọc ESP; - dump memory map trước
ExitBootServices(); - test protocol do DXE driver của bạn publish.
| Mục | Giá trị | Ghi chú |
|---|---|---|
| UEFI Application | Chạy khi được load | Dễ test từ Shell, phù hợp tool/debug. |
| DXE Driver | Chạy bởi dispatcher | Phụ thuộc DSC/FDF/DEPEX. |
| Bootloader | Một dạng UEFI application đặc biệt | Ví dụ bootmgfw.efi, grubx64.efi. |
Cẩn thận với Boot Services
UEFI Application chạy trước khi OS gọi ExitBootServices(). Sau mốc đó, Boot Services không còn dùng được. Vì vậy tool/app nên hiểu rõ service nào là Boot Services, service nào là Runtime Services.
Checklist UEFI Application
Ghi nhớ nhanh
UEFI Application là cách nhanh nhất để biến kiến thức UEFI thành tool chạy thật. Trước khi viết DXE driver phức tạp, hãy thử viết app nhỏ để dump variable, protocol hoặc memory map.
Bài liên quan
Nguồn tham khảo public
Thấy nội dung này hữu ích?
Lưu lại hoặc chia sẻ cho người cũng đang học firmware, BIOS/UEFI và embedded systems.
Nội dung liên quan
Một số bài viết, ghi chú hoặc project có liên quan đến nội dung bạn vừa đọc.
Biến note thành bài viết hoàn chỉnh
Notes là nơi ghi nhanh khái niệm.