EmbeddedPkg/AndroidFastboot: drop dependency on the LinuxLoader
[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 23\r
f6755908
OM
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
34e0bcea 66 CHAR16 *LoadOptions, *NewLoadOptions;\r
f6755908
OM
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
34e0bcea
AB
87 // Initialize Linux command line\r
88 LoadOptions = CatSPrint (NULL, L"%a", KernelArgs);\r
89 if (LoadOptions == NULL) {\r
bd9a5182
OM
90 return EFI_OUT_OF_RESOURCES;\r
91 }\r
92\r
34e0bcea
AB
93 if (RamdiskSize != 0) {\r
94 NewLoadOptions = CatSPrint (LoadOptions, L" initrd=0x%x,0x%x",\r
95 (UINTN)Ramdisk, RamdiskSize);\r
96 FreePool (LoadOptions);\r
97 if (NewLoadOptions == NULL) {\r
98 return EFI_OUT_OF_RESOURCES;\r
99 }\r
100 LoadOptions = NewLoadOptions;\r
bd9a5182
OM
101 }\r
102\r
34e0bcea
AB
103 Status = BdsStartEfiApplication (gImageHandle,\r
104 (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r
105 StrSize (LoadOptions),\r
106 LoadOptions);\r
f6755908
OM
107 if (EFI_ERROR (Status)) {\r
108 DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r
34e0bcea
AB
109 Status = EFI_DEVICE_ERROR;\r
110 goto FreeLoadOptions;\r
f6755908
OM
111 }\r
112\r
113 // If we got here we do a confused face because BootLinuxFdt returned,\r
114 // reporting success.\r
115 DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r
116 return EFI_SUCCESS;\r
34e0bcea
AB
117\r
118FreeLoadOptions:\r
119 FreePool (LoadOptions);\r
120 return Status;\r
f6755908 121}\r