]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
EmbeddedPkg/AndroidFastboot: Use Linux Loader instead of BdsLib
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / Arm / BootAndroidBootImg.c
CommitLineData
f6755908
OM
1/** @file\r
2\r
bd9a5182 3 Copyright (c) 2013-2015, ARM Ltd. All rights reserved.<BR>\r
f6755908
OM
4\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "AndroidFastbootApp.h"\r
16\r
17#include <Protocol/DevicePath.h>\r
18\r
19#include <Library/BdsLib.h>\r
20#include <Library/DevicePathLib.h>\r
bd9a5182
OM
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/UefiLib.h>\r
f6755908
OM
23\r
24#include <Guid/ArmGlobalVariableHob.h>\r
25\r
bd9a5182
OM
26#define LINUX_LOADER_COMMAND_LINE L"%s -f %s -c %s"\r
27\r
28// This GUID is defined in the INGF file of ArmPkg/Application/LinuxLoader\r
29CONST EFI_GUID mLinuxLoaderAppGuid = { 0x701f54f2, 0x0d70, 0x4b89, { 0xbc, 0x0a, 0xd9, 0xca, 0x25, 0x37, 0x90, 0x59 }};\r
30\r
f6755908
OM
31// Device Path representing an image in memory\r
32#pragma pack(1)\r
33typedef struct {\r
34 MEMMAP_DEVICE_PATH Node1;\r
35 EFI_DEVICE_PATH_PROTOCOL End;\r
36} MEMORY_DEVICE_PATH;\r
37#pragma pack()\r
38\r
39STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =\r
40{\r
41 {\r
42 {\r
43 HARDWARE_DEVICE_PATH,\r
44 HW_MEMMAP_DP,\r
45 {\r
46 (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r
47 (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),\r
48 },\r
49 }, // Header\r
50 0, // StartingAddress (set at runtime)\r
51 0 // EndingAddress (set at runtime)\r
52 }, // Node1\r
53 {\r
54 END_DEVICE_PATH_TYPE,\r
55 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
b0fdce95 56 { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
f6755908
OM
57 } // End\r
58};\r
59\r
60EFI_STATUS\r
61BootAndroidBootImg (\r
62 IN UINTN BufferSize,\r
63 IN VOID *Buffer\r
64 )\r
65{\r
f6755908
OM
66 EFI_STATUS Status;\r
67 CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];\r
68 VOID *Kernel;\r
69 UINTN KernelSize;\r
70 VOID *Ramdisk;\r
71 UINTN RamdiskSize;\r
72 MEMORY_DEVICE_PATH KernelDevicePath;\r
73 MEMORY_DEVICE_PATH* RamdiskDevicePath;\r
bd9a5182
OM
74 CHAR16* KernelDevicePathTxt;\r
75 CHAR16* RamdiskDevicePathTxt;\r
76 EFI_DEVICE_PATH* LinuxLoaderDevicePath;\r
77 CHAR16* LoadOptions;\r
f6755908
OM
78\r
79 Status = ParseAndroidBootImg (\r
80 Buffer,\r
81 &Kernel,\r
82 &KernelSize,\r
83 &Ramdisk,\r
84 &RamdiskSize,\r
85 KernelArgs\r
86 );\r
87 if (EFI_ERROR (Status)) {\r
88 return Status;\r
89 }\r
90\r
91 KernelDevicePath = MemoryDevicePathTemplate;\r
92\r
93 // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to\r
94 // appease GCC.\r
95 KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;\r
96 KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;\r
97\r
98 RamdiskDevicePath = NULL;\r
99 if (RamdiskSize != 0) {\r
100 RamdiskDevicePath = (MEMORY_DEVICE_PATH*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL*) &MemoryDevicePathTemplate);\r
101\r
102 RamdiskDevicePath->Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk;\r
103 RamdiskDevicePath->Node1.EndingAddress = ((EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk) + RamdiskSize;\r
104 }\r
105\r
bd9a5182
OM
106 //\r
107 // Boot Linux using the Legacy Linux Loader\r
108 //\r
109\r
110 Status = LocateEfiApplicationInFvByGuid (&mLinuxLoaderAppGuid, &LinuxLoaderDevicePath);\r
111 if (EFI_ERROR (Status)) {\r
112 Print (L"Couldn't Boot Linux: %d\n", Status);\r
113 return EFI_DEVICE_ERROR;\r
114 }\r
115\r
116 KernelDevicePathTxt = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath, FALSE, FALSE);\r
117 if (KernelDevicePathTxt == NULL) {\r
118 return EFI_OUT_OF_RESOURCES;\r
119 }\r
120\r
121 RamdiskDevicePathTxt = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *) RamdiskDevicePath, FALSE, FALSE);\r
122 if (RamdiskDevicePathTxt == NULL) {\r
123 return EFI_OUT_OF_RESOURCES;\r
124 }\r
125\r
126 // Initialize Legacy Linux loader command line\r
127 LoadOptions = CatSPrint (NULL, LINUX_LOADER_COMMAND_LINE, KernelDevicePathTxt, RamdiskDevicePathTxt, KernelArgs);\r
128 if (LoadOptions == NULL) {\r
129 return EFI_OUT_OF_RESOURCES;\r
130 }\r
131\r
132 Status = BdsStartEfiApplication (gImageHandle, LinuxLoaderDevicePath, StrSize (LoadOptions), LoadOptions);\r
f6755908
OM
133 if (EFI_ERROR (Status)) {\r
134 DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r
135 return EFI_DEVICE_ERROR;\r
136 }\r
137\r
138 if (RamdiskDevicePath) {\r
bd9a5182 139 FreePool (RamdiskDevicePathTxt);\r
f6755908
OM
140 FreePool (RamdiskDevicePath);\r
141 }\r
142\r
bd9a5182
OM
143 FreePool (KernelDevicePathTxt);\r
144\r
f6755908
OM
145 // If we got here we do a confused face because BootLinuxFdt returned,\r
146 // reporting success.\r
147 DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r
148 return EFI_SUCCESS;\r
149}\r