-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
92 lines (73 loc) · 1.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <efi.h>
#include <efilib.h>
#include "lib.h"
#include "file.h"
#include "config.h"
static CHAR16*
find_target_file()
{
EFI_STATUS Status;
CHAR16 *TargetKey;
APP_FILE File;
APP_BOOT_ENTRY *Entry;
Status = read_file(SelfDir, L"next_boot", &File);
if (Status == EFI_NOT_FOUND)
{
Print(L"Target file not set. Booting default file.\n");
return GlobalConfig.DefaultFile;
}
else if (EFI_ERROR(Status))
{
Print(L"Could not open target file: %r\n", Status);
goto bailout;
}
TargetKey = read_all(&File);
trim(TargetKey);
FreePool(File.Buffer);
if (TargetKey == NULL)
{
Print(L"Could not read target file!\n");
goto bailout;
}
// delete target file
Status = delete_file(SelfDir, L"next_boot");
if (EFI_ERROR(Status))
{
Print(L"Could not delete target file!\n");
goto bailout;
}
Print(L"Target key is %s\n", TargetKey);
Entry = find_boot_entry(TargetKey);
FreePool(TargetKey);
if (Entry == NULL)
{
Print(L"Could not find target to boot!\n");
goto bailout;
}
return Entry->File;
bailout:
Print(L"Press any key to continue...\n");
wait_for_keystroke();
return GlobalConfig.DefaultFile;
}
EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
InitializeLib(ImageHandle, SystemTable);
SelfImageHandle = ImageHandle;
SelfDir = SelfRootDir = NULL;
SelfDirPath = NULL;
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
Status = init_lib(ImageHandle);
WAIT_ERROR(Status);
Status = load_config();
WAIT_ERROR(Status);
CHAR16 *TargetFile;
Print(L"Loading target file...\n");
TargetFile = find_target_file();
Status = run_file(TargetFile);
WAIT_ERROR(Status);
return EFI_SUCCESS;
}