Last active
September 18, 2019 17:03
-
-
Save 196Ikuchil/c1c59537b4dab4707c20aaa84b74b727 to your computer and use it in GitHub Desktop.
UEFI mini camp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Uefi.h> | |
#include <Library/UefiLib.h> | |
#include <Library/UefiBootServicesTableLib.h> | |
#include <Library/PrintLib.h> | |
#include <Library/BaseMemoryLib.h> | |
#include <Library/MemoryAllocationLib.h> | |
#include <Protocol/LoadedImage.h> | |
#include <Protocol/SimpleFileSystem.h> | |
#include "Memory_map.h" | |
//省略.. | |
EFI_STATUS OpenRootDir(EFI_HANDLE image_handle, EFI_FILE_PROTOCOL** root) { | |
EFI_STATUS status; | |
EFI_LOADED_IMAGE_PROTOCOL* loaded_image; | |
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs; | |
status = gBS->OpenProtocol( | |
image_handle, | |
&gEfiLoadedImageProtocolGuid, | |
(VOID**)&loaded_image, | |
image_handle, | |
NULL, | |
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); | |
if (EFI_ERROR(status)) { | |
return status; | |
} | |
status = gBS->OpenProtocol( | |
loaded_image->DeviceHandle, | |
&gEfiSimpleFileSystemProtocolGuid, | |
(VOID**)&fs, | |
image_handle, | |
NULL, | |
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL); | |
if (EFI_ERROR(status)) { | |
return status; | |
} | |
return fs->OpenVolume(fs, root); | |
} | |
EFI_STATUS EFIAPI UefiMain ( | |
IN EFI_HANDLE image_handle, | |
IN EFI_SYSTEM_TABLE *SystemTable | |
) | |
{ | |
Print(L"Hello EDK II.\n"); | |
EFI_STATUS status; | |
//メモリ取得処理省略... | |
EFI_FILE_PROTOCOL *root_dir; | |
status = OpenRootDir(image_handle, &root_dir); | |
if (EFI_ERROR(status)) { | |
Print(L"failed to open root directory: %r\n", status); | |
Halt(); | |
} | |
Print(L"OpenRootDir : %r\n", status); | |
EFI_FILE_PROTOCOL* memmap_file; | |
status = root_dir->Open( //ここでDevice Errorが発生 | |
root_dir, &memmap_file, L"\\memmap", | |
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); | |
if (EFI_ERROR(status)) { | |
Print(L"failed to open file '\\memmap': %r\n", status); | |
Print(L"Ignored.\n"); | |
} else { | |
status = SaveMemoryMap(&memmap, memmap_file); | |
if (EFI_ERROR(status)) { | |
Print(L"failed to save memory map: %r\n", status); | |
Halt(); | |
} | |
status = memmap_file->Close(memmap_file); | |
if (EFI_ERROR(status)) { | |
Print(L"failed to close memory map: %r\n", status); | |
Halt(); | |
} | |
} | |
while (1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment