Skip to content

Instantly share code, notes, and snippets.

@196Ikuchil
Last active September 18, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 196Ikuchil/c1c59537b4dab4707c20aaa84b74b727 to your computer and use it in GitHub Desktop.
Save 196Ikuchil/c1c59537b4dab4707c20aaa84b74b727 to your computer and use it in GitHub Desktop.
UEFI mini camp
#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