ArmPkg/BdsLib: Replaced BdsLoadApplication() by LocateEfiApplicationInFv()
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / Arm / BootAndroidBootImg.c
CommitLineData
f6755908
OM
1/** @file\r
2\r
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r
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
21\r
22#include <Guid/ArmGlobalVariableHob.h>\r
23\r
24// Device Path representing an image in memory\r
25#pragma pack(1)\r
26typedef struct {\r
27 MEMMAP_DEVICE_PATH Node1;\r
28 EFI_DEVICE_PATH_PROTOCOL End;\r
29} MEMORY_DEVICE_PATH;\r
30#pragma pack()\r
31\r
32STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =\r
33{\r
34 {\r
35 {\r
36 HARDWARE_DEVICE_PATH,\r
37 HW_MEMMAP_DP,\r
38 {\r
39 (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r
40 (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),\r
41 },\r
42 }, // Header\r
43 0, // StartingAddress (set at runtime)\r
44 0 // EndingAddress (set at runtime)\r
45 }, // Node1\r
46 {\r
47 END_DEVICE_PATH_TYPE,\r
48 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
b0fdce95 49 { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
f6755908
OM
50 } // End\r
51};\r
52\r
53EFI_STATUS\r
54BootAndroidBootImg (\r
55 IN UINTN BufferSize,\r
56 IN VOID *Buffer\r
57 )\r
58{\r
f6755908
OM
59 EFI_STATUS Status;\r
60 CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];\r
61 VOID *Kernel;\r
62 UINTN KernelSize;\r
63 VOID *Ramdisk;\r
64 UINTN RamdiskSize;\r
65 MEMORY_DEVICE_PATH KernelDevicePath;\r
66 MEMORY_DEVICE_PATH* RamdiskDevicePath;\r
67\r
68 Status = ParseAndroidBootImg (\r
69 Buffer,\r
70 &Kernel,\r
71 &KernelSize,\r
72 &Ramdisk,\r
73 &RamdiskSize,\r
74 KernelArgs\r
75 );\r
76 if (EFI_ERROR (Status)) {\r
77 return Status;\r
78 }\r
79\r
80 KernelDevicePath = MemoryDevicePathTemplate;\r
81\r
82 // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to\r
83 // appease GCC.\r
84 KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;\r
85 KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;\r
86\r
87 RamdiskDevicePath = NULL;\r
88 if (RamdiskSize != 0) {\r
89 RamdiskDevicePath = (MEMORY_DEVICE_PATH*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL*) &MemoryDevicePathTemplate);\r
90\r
91 RamdiskDevicePath->Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk;\r
92 RamdiskDevicePath->Node1.EndingAddress = ((EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk) + RamdiskSize;\r
93 }\r
94\r
f6755908
OM
95 Status = BdsBootLinuxFdt (\r
96 (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r
97 (EFI_DEVICE_PATH_PROTOCOL *) RamdiskDevicePath,\r
6332ffb0 98 KernelArgs\r
f6755908
OM
99 );\r
100 if (EFI_ERROR (Status)) {\r
101 DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r
102 return EFI_DEVICE_ERROR;\r
103 }\r
104\r
105 if (RamdiskDevicePath) {\r
106 FreePool (RamdiskDevicePath);\r
107 }\r
108\r
109 // If we got here we do a confused face because BootLinuxFdt returned,\r
110 // reporting success.\r
111 DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r
112 return EFI_SUCCESS;\r
113}\r