comparison gnu-efi-3.0.12/apps/bootloader.c @ 1:cbcaeba32076

add shellscript
author nana
date Tue, 11 Apr 2023 11:50:25 +0900
parents bootloader.c@f434d6ab8db1
children c2a38c3c71ab
comparison
equal deleted inserted replaced
0:f434d6ab8db1 1:cbcaeba32076
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 EFI_DEVICE_PATH *Path;
9 EFI_LOADED_IMAGE *LoadedImageParent;
10 EFI_LOADED_IMAGE *LoadedImage;
11 EFI_HANDLE Image;
12 CHAR16 *Options = L"root=/dev/sda2 rootfstype=btrfs rw quiet splash";
13 EFI_STATUS Status=EFI_SUCCESS;
14
15 InitializeLib(ImageHandle, SystemTable);
16 Print(L"Hello, EFI!\n");
17
18 Status = uefi_call_wrapper(BS->OpenProtocol, 6, ImageHandle, &LoadedImageProtocol,(void**)&LoadedImageParent, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
19 if (EFI_ERROR(Status)) {
20 Print(L"Could not get LoadedImageProtocol handler %r\n", Status);
21 return Status;
22 }
23 Print(L"Hello,2!\n");
24 Path = FileDevicePath(LoadedImageParent->DeviceHandle, L"\\OS");
25 if (Path == NULL) {
26 Print(L"Could not get device path.");
27 return EFI_INVALID_PARAMETER;
28 }
29 Print(L"Hello,3!\n");
30 Status = uefi_call_wrapper(BS->LoadImage, 6, FALSE, ImageHandle, Path, NULL, 0, &Image);
31 if (EFI_ERROR(Status)) {
32 Print(L"Could not load %r", Status);
33 FreePool(Path);
34 return Status;
35 }
36 Print(L"Hello,4!\n");
37 Status = uefi_call_wrapper(BS->OpenProtocol, 6, Image, &LoadedImageProtocol, (void**)&LoadedImage, ImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
38 if (EFI_ERROR(Status)) {
39 Print(L"Could not get LoadedImageProtocol handler %r\n", Status);
40 uefi_call_wrapper(BS->UnloadImage, 1, Image);
41 FreePool(Path);
42 return Status;
43 }
44 Print(L"Hello,5!\n");
45 LoadedImage->LoadOptions = Options;
46 LoadedImage->LoadOptionsSize = (StrLen(LoadedImage->LoadOptions)+1) * sizeof(CHAR16);
47
48 Print(L"Hello,6!\n");
49 Status = uefi_call_wrapper(BS->StartImage, 3, Image, NULL, NULL);
50 uefi_call_wrapper(BS->UnloadImage, 1, Image);
51 FreePool(Path);
52 Print(L"Hello,7!\n");
53
54 return EFI_SUCCESS;
55 }