-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBoot.c
75 lines (60 loc) · 1.82 KB
/
Boot.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
#include "Boot.h"
#include <Protocol/LoadedImage.h>
EFI_STATUS Boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* systab)
{
EFI_GUID LoadedImageProtocolGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
CHAR16 boot_filename[] = L"\\EFI\\Microsoft\\Boot\\bootmgfw.orig.efi";
EFI_STATUS res;
//load boot file
void* data = NULL;
UINTN data_size = 0;
EFI_DEVICE_PATH_PROTOCOL* file_path;
res = LoadFile(ImageHandle, systab, boot_filename, &data, &data_size,
&file_path);
if (res == EFI_NOT_FOUND )
{
ErrorPrint(L"Could not find boot manager.\r\n");
return EFI_NOT_FOUND ;
}
else if (res)
{
ErrorPrint(L"Loading boot manager image failed.\r\n");
return EFI_LOAD_ERROR ;
}
//get this image's info
EFI_LOADED_IMAGE_PROTOCOL* img_proto;
res = systab->BootServices->HandleProtocol(ImageHandle,
&LoadedImageProtocolGuid, (void**) &img_proto);
if (res)
{
systab->BootServices->FreePool(data);
ErrorPrint(L"Failed to get image info protocol. (Error %d)\r\n", res);
return EFI_LOAD_ERROR ;
}
//Load the image
EFI_HANDLE new_img_handle;
res = systab->BootServices->LoadImage(FALSE, ImageHandle, NULL, data,
data_size, &new_img_handle);
systab->BootServices->FreePool(data);
if (res)
{
ErrorPrint(L"Failed to load new image. (Error %d)\r\n", res);
return EFI_LOAD_ERROR ;
}
//get new image info
EFI_LOADED_IMAGE_PROTOCOL* new_img_proto;
res = systab->BootServices->HandleProtocol(new_img_handle,
&LoadedImageProtocolGuid, (void**) &new_img_proto);
if (res)
{
ErrorPrint(L"Failed to get new image information. (Error %d)\r\n", res);
return EFI_LOAD_ERROR ;
}
//set image data
new_img_proto->DeviceHandle = img_proto->DeviceHandle;
new_img_proto->ParentHandle = NULL;
new_img_proto->FilePath = file_path;
//Start the new image
systab->BootServices->StartImage(new_img_handle, 0, NULL );
return EFI_SUCCESS;
}