]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
BaseTools/Capsule: Do not support -o with --dump-info
[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
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Library/AndroidBootImgLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
fa74dd22
JN
18#include <Library/DebugLib.h>\r
19#include <Library/DevicePathLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22\r
23#include <Protocol/BlockIo.h>\r
24#include <Protocol/DevicePathFromText.h>\r
25\r
26/* Validate the node is media hard drive type */\r
27EFI_STATUS\r
28ValidateAndroidMediaDevicePath (\r
29 IN EFI_DEVICE_PATH *DevicePath\r
30 )\r
31{\r
32 EFI_DEVICE_PATH_PROTOCOL *Node, *NextNode;\r
33\r
34 NextNode = DevicePath;\r
35 while (NextNode != NULL) {\r
36 Node = NextNode;\r
a64d5872
LL
37 if (Node->Type == MEDIA_DEVICE_PATH &&\r
38 Node->SubType == MEDIA_HARDDRIVE_DP) {\r
fa74dd22
JN
39 return EFI_SUCCESS;\r
40 }\r
41 NextNode = NextDevicePathNode (Node);\r
42 }\r
43 return EFI_INVALID_PARAMETER;\r
44}\r
45\r
46EFI_STATUS\r
47EFIAPI\r
48AndroidBootAppEntryPoint (\r
49 IN EFI_HANDLE ImageHandle,\r
50 IN EFI_SYSTEM_TABLE *SystemTable\r
51 )\r
52{\r
53 EFI_STATUS Status;\r
54 CHAR16 *BootPathStr;\r
55 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;\r
56 EFI_DEVICE_PATH *DevicePath;\r
57 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
58 UINT32 MediaId, BlockSize;\r
59 VOID *Buffer;\r
60 EFI_HANDLE Handle;\r
61 UINTN BootImgSize;\r
62\r
63 BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);\r
64 ASSERT (BootPathStr != NULL);\r
65 Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL,\r
66 (VOID **)&EfiDevicePathFromTextProtocol);\r
67 ASSERT_EFI_ERROR(Status);\r
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
76 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid,\r
77 &DevicePath, &Handle);\r
78 if (EFI_ERROR (Status)) {\r
79 return Status;\r
80 }\r
81\r
82 Status = gBS->OpenProtocol (\r
83 Handle,\r
84 &gEfiBlockIoProtocolGuid,\r
85 (VOID **) &BlockIo,\r
86 gImageHandle,\r
87 NULL,\r
88 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
89 );\r
90 if (EFI_ERROR (Status)) {\r
91 DEBUG ((DEBUG_ERROR, "Failed to get BlockIo: %r\n", Status));\r
92 return Status;\r
93 }\r
94\r
95 MediaId = BlockIo->Media->MediaId;\r
96 BlockSize = BlockIo->Media->BlockSize;\r
97 Buffer = AllocatePages (EFI_SIZE_TO_PAGES (sizeof(ANDROID_BOOTIMG_HEADER)));\r
98 if (Buffer == NULL) {\r
99 return EFI_BUFFER_TOO_SMALL;\r
100 }\r
101 /* Load header of boot.img */\r
102 Status = BlockIo->ReadBlocks (\r
103 BlockIo,\r
104 MediaId,\r
105 0,\r
106 BlockSize,\r
107 Buffer\r
108 );\r
109 Status = AndroidBootImgGetImgSize (Buffer, &BootImgSize);\r
110 if (EFI_ERROR (Status)) {\r
111 DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status));\r
112 return Status;\r
113 }\r
114 BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize);\r
115 FreePages (Buffer, EFI_SIZE_TO_PAGES (sizeof(ANDROID_BOOTIMG_HEADER)));\r
116\r
117 /* Both PartitionStart and PartitionSize are counted as block size. */\r
118 Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BootImgSize));\r
119 if (Buffer == NULL) {\r
120 return EFI_BUFFER_TOO_SMALL;\r
121 }\r
122\r
123 /* Load header of boot.img */\r
124 Status = BlockIo->ReadBlocks (\r
125 BlockIo,\r
126 MediaId,\r
127 0,\r
128 BootImgSize,\r
129 Buffer\r
130 );\r
131 if (EFI_ERROR (Status)) {\r
132 DEBUG ((DEBUG_ERROR, "Failed to read blocks: %r\n", Status));\r
133 goto EXIT;\r
134 }\r
135\r
136 Status = AndroidBootImgBoot (Buffer, BootImgSize);\r
137\r
138EXIT:\r
139 return Status;\r
140}\r