commit d29cbf94bdd950b87d2605ba1433047e4a40b8e4
parent 276d034a1c7bca2f6c56fae51461d14b2b70010e
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 29 Mar 2024 14:41:11 +0900
move open_root to utils.c
Diffstat:
M | loader.c | | | 32 | -------------------------------- |
M | utils.c | | | 31 | +++++++++++++++++++++++++++++-- |
M | utils.h | | | 7 | ++++++- |
3 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/loader.c b/loader.c
@@ -1,10 +1,6 @@
#include "uefi.h"
#include "utils.h"
-#define NULL 0L
-
-EFI_STATUS open_root(EFI_HANDLE, EFI_FILE_PROTOCOL **);
-
EFI_SYSTEM_TABLE *SystemTable;
EFI_STATUS
@@ -88,7 +84,6 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab)
efi_printf("close file: %d\n", stat);
return stat;
}
-
mmsize = 8196;
stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver);
if (stat != EFI_SUCCESS) {
@@ -105,30 +100,3 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab)
return EFI_SUCCESS;
}
-
-EFI_STATUS
-open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root)
-{
- EFI_STATUS stat;
- EFI_LOADED_IMAGE_PROTOCOL *li;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
-
- stat = SystemTable->BootServices->OpenProtocol(
- ImageHandle, &EFI_LOADED_IMAGE_PROTOCOL_GUID,
- (VOID **) &li, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
- );
- if (stat != EFI_SUCCESS) {
- return stat;
- }
-
- stat = SystemTable->BootServices->OpenProtocol(
- li->DeviceHandle, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
- (VOID **) &fs, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
- );
- if (stat != EFI_SUCCESS) {
- return stat;
- }
-
- stat = fs->OpenVolume(fs, root);
- return stat;
-}
diff --git a/utils.c b/utils.c
@@ -125,6 +125,34 @@ efi_printf(char *fmt, ...)
}
EFI_STATUS
+open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root)
+{
+ EFI_STATUS stat;
+ EFI_LOADED_IMAGE_PROTOCOL *li;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
+
+ stat = SystemTable->BootServices->OpenProtocol(
+ ImageHandle, &EFI_LOADED_IMAGE_PROTOCOL_GUID,
+ (VOID **) &li, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
+ );
+ if (stat != EFI_SUCCESS) {
+ return stat;
+ }
+
+ stat = SystemTable->BootServices->OpenProtocol(
+ li->DeviceHandle, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
+ (VOID **) &fs, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
+ );
+ if (stat != EFI_SUCCESS) {
+ return stat;
+ }
+
+ stat = fs->OpenVolume(fs, root);
+ return stat;
+}
+
+
+EFI_STATUS
read_ehdr(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr)
{
EFI_STATUS stat;
@@ -205,4 +233,4 @@ load_elf(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr phdr[])
}
}
return EFI_SUCCESS;
-}
-\ No newline at end of file
+}
diff --git a/utils.h b/utils.h
@@ -2,6 +2,8 @@
extern EFI_SYSTEM_TABLE *SystemTable;
+#define NULL 0L
+
// Printh converts the integer into a string of hex representation.
// It returns the second argument.
// The second argument should have length of 19 ("0x" + "0123456789abcdef" + "\0").
@@ -13,11 +15,14 @@ CHAR16 *sprinth(UINT64, CHAR16[19]);
// It returns s.
char *wstr2str(CHAR16 *s16, char *s8);
-// Efi_rintf prints formatted string to ConOut.
+// Efi_printf prints formatted string to ConOut.
// Can't format a string longer than 1024 CHAR16s.
// It returns number of CHAR16s written excluding the final NULL.
int efi_printf(char *fmt, ...);
+// Open_root opens the root directory of the efi image.
+EFI_STATUS open_root(EFI_HANDLE, EFI_FILE_PROTOCOL **);
+
// ELF header.
typedef struct {
unsigned char ident[16];