0
|
1 #include<efi.h>
|
|
2 #include<efilib.h>
|
|
3
|
|
4
|
|
5 EFI_STATUS
|
|
6 efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
|
|
7 {
|
|
8
|
|
9 // UINTN UartBase = 0x09000000;
|
|
10 // UINTN UartClk = 24000000;
|
|
11 //CHAR8 buffer[256];
|
|
12 //UINTN bufferSize;
|
|
13
|
|
14 EFI_DEVICE_PATH *Path;
|
|
15 EFI_LOADED_IMAGE *LoadedImageParent;
|
|
16 EFI_LOADED_IMAGE *LoadedImage;
|
|
17 EFI_HANDLE Image;
|
|
18 CHAR16 *Options = L"root=/dev/sda2 rootfstype=btrfs rw quiet splash";
|
|
19 EFI_STATUS Status=EFI_SUCCESS;
|
|
20
|
|
21 InitializeLib(ImageHandle, SystemTable);
|
|
22 Print(L"Hello, EFI!\n");
|
|
23
|
|
24 // Status = InitializeUart(UartBase, UartClk);
|
|
25 // if (EFI_ERROR(Status)) {
|
|
26 // Print(L"Error initializing UART device: %r\n", Status);
|
|
27 // return Status;
|
|
28 // }
|
|
29 // Print(L"Hello, UART1!\n");
|
|
30
|
|
31 // Read kernel image from UART
|
|
32 // bufferSize = sizeof(buffer);
|
|
33 // Status = ReadUart(UartBase, &bufferSize, buffer);
|
|
34 // if (EFI_ERROR(Status)) {
|
|
35 // Print(L"Error reading kernel image from UART: %r\n", Status);
|
|
36 // return Status;
|
|
37 // }
|
|
38
|
|
39 // Print(L"Hello, UART2!\n");
|
|
40
|
|
41 // Status = uefi_call_wrapper(BS->OpenProtocol, 6, ImageHandle, &LoadedImageProtocol,(void**)&LoadedImageParent, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
|
42 // if (EFI_ERROR(Status)) {
|
|
43 // Print(L"Could not get LoadedImageProtocol handler %r\n", Status);
|
|
44 // return Status;
|
|
45 // }
|
|
46
|
|
47 // Check the validity of the received data
|
|
48 // if (!validate_image(buffer, bufferSize)) {
|
|
49 // Print(L"Invalid kernel image received\n");
|
|
50 // return EFI_INVALID_PARAMETER;
|
|
51 // }
|
|
52
|
|
53
|
|
54 Print(L"Hello,2!\n");
|
|
55 Path = FileDevicePath(LoadedImageParent->DeviceHandle, L"\\kernel.elf");
|
|
56 if (Path == NULL) {
|
|
57 Print(L"Could not get device path.");
|
|
58 return EFI_INVALID_PARAMETER;
|
|
59 }
|
|
60 Print(L"Hello,3!\n");
|
|
61 Status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, ImageHandle, Path, NULL, 0, &Image);
|
|
62 if (EFI_ERROR(Status)) {
|
|
63 Print(L"Could not load %r", Status);
|
|
64 FreePool(Path);
|
|
65 return Status;
|
|
66 }
|
|
67 Print(L"Hello,4!\n");
|
|
68 Status = uefi_call_wrapper(BS->OpenProtocol, 6, Image, &LoadedImageProtocol, (void**)&LoadedImage, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
|
69 if (EFI_ERROR(Status)) {
|
|
70 Print(L"Could not get LoadedImageProtocol handler %r\n", Status);
|
|
71 uefi_call_wrapper(BS->UnloadImage, 1, Image);
|
|
72 FreePool(Path);
|
|
73 return Status;
|
|
74 }
|
|
75 Print(L"Hello,5!\n");
|
|
76 LoadedImage->LoadOptions = Options;
|
|
77 LoadedImage->LoadOptionsSize = (StrLen(LoadedImage->LoadOptions)+1) * sizeof(CHAR16);
|
|
78
|
|
79 Print(L"Hello,6!\n");
|
|
80 Status = uefi_call_wrapper(BS->StartImage, 3, Image, NULL, NULL);
|
|
81 uefi_call_wrapper(BS->UnloadImage, 1, Image);
|
|
82 FreePool(Path);
|
|
83 Print(L"Hello,7!\n");
|
|
84
|
|
85 return EFI_SUCCESS;
|
|
86 }
|
|
87
|