TianoCore EDK2 master
Loading...
Searching...
No Matches
AndroidBootApp.c
Go to the documentation of this file.
1
12#include <Library/DebugLib.h>
16
17#include <Protocol/BlockIo.h>
19
20/* Validate the node is media hard drive type */
22ValidateAndroidMediaDevicePath (
23 IN EFI_DEVICE_PATH *DevicePath
24 )
25{
26 EFI_DEVICE_PATH_PROTOCOL *Node, *NextNode;
27
28 NextNode = DevicePath;
29 while (NextNode != NULL) {
30 Node = NextNode;
31 if ((Node->Type == MEDIA_DEVICE_PATH) &&
32 (Node->SubType == MEDIA_HARDDRIVE_DP))
33 {
34 return EFI_SUCCESS;
35 }
36
37 NextNode = NextDevicePathNode (Node);
38 }
39
40 return EFI_INVALID_PARAMETER;
41}
42
44EFIAPI
45AndroidBootAppEntryPoint (
46 IN EFI_HANDLE ImageHandle,
47 IN EFI_SYSTEM_TABLE *SystemTable
48 )
49{
50 EFI_STATUS Status;
51 CHAR16 *BootPathStr;
52 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
53 EFI_DEVICE_PATH *DevicePath;
54 EFI_BLOCK_IO_PROTOCOL *BlockIo;
55 UINT32 MediaId, BlockSize;
56 VOID *Buffer;
57 EFI_HANDLE Handle;
58 UINTN BootImgSize;
59
60 BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
61 ASSERT (BootPathStr != NULL);
62 Status = gBS->LocateProtocol (
63 &gEfiDevicePathFromTextProtocolGuid,
64 NULL,
65 (VOID **)&EfiDevicePathFromTextProtocol
66 );
67 ASSERT_EFI_ERROR (Status);
68 DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);
69 ASSERT (DevicePath != NULL);
70
71 Status = ValidateAndroidMediaDevicePath (DevicePath);
72 if (EFI_ERROR (Status)) {
73 return Status;
74 }
75
76 Status = gBS->LocateDevicePath (
77 &gEfiDevicePathProtocolGuid,
78 &DevicePath,
79 &Handle
80 );
81 if (EFI_ERROR (Status)) {
82 return Status;
83 }
84
85 Status = gBS->OpenProtocol (
86 Handle,
87 &gEfiBlockIoProtocolGuid,
88 (VOID **)&BlockIo,
90 NULL,
91 EFI_OPEN_PROTOCOL_GET_PROTOCOL
92 );
93 if (EFI_ERROR (Status)) {
94 DEBUG ((DEBUG_ERROR, "Failed to get BlockIo: %r\n", Status));
95 return Status;
96 }
97
98 MediaId = BlockIo->Media->MediaId;
99 BlockSize = BlockIo->Media->BlockSize;
101 if (Buffer == NULL) {
102 return EFI_BUFFER_TOO_SMALL;
103 }
104
105 /* Load header of boot.img */
106 Status = BlockIo->ReadBlocks (
107 BlockIo,
108 MediaId,
109 0,
110 BlockSize,
111 Buffer
112 );
113 Status = AndroidBootImgGetImgSize (Buffer, &BootImgSize);
114 if (EFI_ERROR (Status)) {
115 DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status));
116 return Status;
117 }
118
119 BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize);
121
122 /* Both PartitionStart and PartitionSize are counted as block size. */
123 Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BootImgSize));
124 if (Buffer == NULL) {
125 return EFI_BUFFER_TOO_SMALL;
126 }
127
128 /* Load header of boot.img */
129 Status = BlockIo->ReadBlocks (
130 BlockIo,
131 MediaId,
132 0,
133 BootImgSize,
134 Buffer
135 );
136 if (EFI_ERROR (Status)) {
137 DEBUG ((DEBUG_ERROR, "Failed to read blocks: %r\n", Status));
138 goto EXIT;
139 }
140
141 Status = AndroidBootImgBoot (Buffer, BootImgSize);
142
143EXIT:
144 return Status;
145}
UINT64 UINTN
#define MEDIA_HARDDRIVE_DP
Definition: DevicePath.h:1014
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
#define NULL
Definition: Base.h:319
#define ALIGN_VALUE(Value, Alignment)
Definition: Base.h:948
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
VOID *EFIAPI AllocatePages(IN UINTN Pages)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS