]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidBoot / AndroidBootApp.c
CommitLineData
fa74dd22
JN
1/** @file\r
2\r
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r
4 Copyright (c) 2017, Linaro. All rights reserved.\r
5\r
878b807a 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
fa74dd22
JN
7\r
8**/\r
9\r
10#include <Library/AndroidBootImgLib.h>\r
11#include <Library/BaseMemoryLib.h>\r
fa74dd22
JN
12#include <Library/DebugLib.h>\r
13#include <Library/DevicePathLib.h>\r
14#include <Library/MemoryAllocationLib.h>\r
15#include <Library/UefiBootServicesTableLib.h>\r
16\r
17#include <Protocol/BlockIo.h>\r
18#include <Protocol/DevicePathFromText.h>\r
19\r
20/* Validate the node is media hard drive type */\r
21EFI_STATUS\r
22ValidateAndroidMediaDevicePath (\r
e7108d0e 23 IN EFI_DEVICE_PATH *DevicePath\r
fa74dd22
JN
24 )\r
25{\r
e7108d0e 26 EFI_DEVICE_PATH_PROTOCOL *Node, *NextNode;\r
fa74dd22
JN
27\r
28 NextNode = DevicePath;\r
29 while (NextNode != NULL) {\r
30 Node = NextNode;\r
e7108d0e
MK
31 if ((Node->Type == MEDIA_DEVICE_PATH) &&\r
32 (Node->SubType == MEDIA_HARDDRIVE_DP))\r
33 {\r
fa74dd22
JN
34 return EFI_SUCCESS;\r
35 }\r
e7108d0e 36\r
fa74dd22
JN
37 NextNode = NextDevicePathNode (Node);\r
38 }\r
e7108d0e 39\r
fa74dd22
JN
40 return EFI_INVALID_PARAMETER;\r
41}\r
42\r
43EFI_STATUS\r
44EFIAPI\r
45AndroidBootAppEntryPoint (\r
e7108d0e
MK
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
fa74dd22
JN
48 )\r
49{\r
50 EFI_STATUS Status;\r
51 CHAR16 *BootPathStr;\r
52 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;\r
53 EFI_DEVICE_PATH *DevicePath;\r
54 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
55 UINT32 MediaId, BlockSize;\r
56 VOID *Buffer;\r
57 EFI_HANDLE Handle;\r
58 UINTN BootImgSize;\r
59\r
60 BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);\r
61 ASSERT (BootPathStr != NULL);\r
e7108d0e
MK
62 Status = gBS->LocateProtocol (\r
63 &gEfiDevicePathFromTextProtocolGuid,\r
64 NULL,\r
65 (VOID **)&EfiDevicePathFromTextProtocol\r
66 );\r
67 ASSERT_EFI_ERROR (Status);\r
fa74dd22
JN
68 DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);\r
69 ASSERT (DevicePath != NULL);\r
70\r
71 Status = ValidateAndroidMediaDevicePath (DevicePath);\r
72 if (EFI_ERROR (Status)) {\r
73 return Status;\r
74 }\r
75\r
e7108d0e
MK
76 Status = gBS->LocateDevicePath (\r
77 &gEfiDevicePathProtocolGuid,\r
78 &DevicePath,\r
79 &Handle\r
80 );\r
fa74dd22
JN
81 if (EFI_ERROR (Status)) {\r
82 return Status;\r
83 }\r
84\r
85 Status = gBS->OpenProtocol (\r
86 Handle,\r
87 &gEfiBlockIoProtocolGuid,\r
e7108d0e 88 (VOID **)&BlockIo,\r
fa74dd22
JN
89 gImageHandle,\r
90 NULL,\r
91 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
92 );\r
93 if (EFI_ERROR (Status)) {\r
94 DEBUG ((DEBUG_ERROR, "Failed to get BlockIo: %r\n", Status));\r
95 return Status;\r
96 }\r
97\r
e7108d0e 98 MediaId = BlockIo->Media->MediaId;\r
fa74dd22 99 BlockSize = BlockIo->Media->BlockSize;\r
e7108d0e 100 Buffer = AllocatePages (EFI_SIZE_TO_PAGES (sizeof (ANDROID_BOOTIMG_HEADER)));\r
fa74dd22
JN
101 if (Buffer == NULL) {\r
102 return EFI_BUFFER_TOO_SMALL;\r
103 }\r
e7108d0e 104\r
fa74dd22
JN
105 /* Load header of boot.img */\r
106 Status = BlockIo->ReadBlocks (\r
107 BlockIo,\r
108 MediaId,\r
109 0,\r
110 BlockSize,\r
111 Buffer\r
112 );\r
113 Status = AndroidBootImgGetImgSize (Buffer, &BootImgSize);\r
114 if (EFI_ERROR (Status)) {\r
115 DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status));\r
116 return Status;\r
117 }\r
e7108d0e 118\r
fa74dd22 119 BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize);\r
e7108d0e 120 FreePages (Buffer, EFI_SIZE_TO_PAGES (sizeof (ANDROID_BOOTIMG_HEADER)));\r
fa74dd22
JN
121\r
122 /* Both PartitionStart and PartitionSize are counted as block size. */\r
123 Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BootImgSize));\r
124 if (Buffer == NULL) {\r
125 return EFI_BUFFER_TOO_SMALL;\r
126 }\r
127\r
128 /* Load header of boot.img */\r
129 Status = BlockIo->ReadBlocks (\r
130 BlockIo,\r
131 MediaId,\r
132 0,\r
133 BootImgSize,\r
134 Buffer\r
135 );\r
136 if (EFI_ERROR (Status)) {\r
137 DEBUG ((DEBUG_ERROR, "Failed to read blocks: %r\n", Status));\r
138 goto EXIT;\r
139 }\r
140\r
141 Status = AndroidBootImgBoot (Buffer, BootImgSize);\r
142\r
143EXIT:\r
144 return Status;\r
145}\r