]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
MdeModulePkg/EbcDebugger: Compare ASCII char with '\0'
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / Arm / BootAndroidBootImg.c
... / ...
CommitLineData
1/** @file\r
2\r
3 Copyright (c) 2013-2015, 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#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/UefiLib.h>\r
23\r
24#define LINUX_LOADER_COMMAND_LINE L"%s -f %s -c %s"\r
25\r
26// This GUID is defined in the INGF file of ArmPkg/Application/LinuxLoader\r
27CONST EFI_GUID mLinuxLoaderAppGuid = { 0x701f54f2, 0x0d70, 0x4b89, { 0xbc, 0x0a, 0xd9, 0xca, 0x25, 0x37, 0x90, 0x59 }};\r
28\r
29// Device Path representing an image in memory\r
30#pragma pack(1)\r
31typedef struct {\r
32 MEMMAP_DEVICE_PATH Node1;\r
33 EFI_DEVICE_PATH_PROTOCOL End;\r
34} MEMORY_DEVICE_PATH;\r
35#pragma pack()\r
36\r
37STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =\r
38{\r
39 {\r
40 {\r
41 HARDWARE_DEVICE_PATH,\r
42 HW_MEMMAP_DP,\r
43 {\r
44 (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r
45 (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),\r
46 },\r
47 }, // Header\r
48 0, // StartingAddress (set at runtime)\r
49 0 // EndingAddress (set at runtime)\r
50 }, // Node1\r
51 {\r
52 END_DEVICE_PATH_TYPE,\r
53 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
54 { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
55 } // End\r
56};\r
57\r
58EFI_STATUS\r
59BootAndroidBootImg (\r
60 IN UINTN BufferSize,\r
61 IN VOID *Buffer\r
62 )\r
63{\r
64 EFI_STATUS Status;\r
65 CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];\r
66 VOID *Kernel;\r
67 UINTN KernelSize;\r
68 VOID *Ramdisk;\r
69 UINTN RamdiskSize;\r
70 MEMORY_DEVICE_PATH KernelDevicePath;\r
71 MEMORY_DEVICE_PATH* RamdiskDevicePath;\r
72 CHAR16* KernelDevicePathTxt;\r
73 CHAR16* RamdiskDevicePathTxt;\r
74 EFI_DEVICE_PATH* LinuxLoaderDevicePath;\r
75 CHAR16* LoadOptions;\r
76\r
77 Status = ParseAndroidBootImg (\r
78 Buffer,\r
79 &Kernel,\r
80 &KernelSize,\r
81 &Ramdisk,\r
82 &RamdiskSize,\r
83 KernelArgs\r
84 );\r
85 if (EFI_ERROR (Status)) {\r
86 return Status;\r
87 }\r
88\r
89 KernelDevicePath = MemoryDevicePathTemplate;\r
90\r
91 // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to\r
92 // appease GCC.\r
93 KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;\r
94 KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;\r
95\r
96 RamdiskDevicePath = NULL;\r
97 if (RamdiskSize != 0) {\r
98 RamdiskDevicePath = (MEMORY_DEVICE_PATH*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL*) &MemoryDevicePathTemplate);\r
99\r
100 RamdiskDevicePath->Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk;\r
101 RamdiskDevicePath->Node1.EndingAddress = ((EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk) + RamdiskSize;\r
102 }\r
103\r
104 //\r
105 // Boot Linux using the Legacy Linux Loader\r
106 //\r
107\r
108 Status = LocateEfiApplicationInFvByGuid (&mLinuxLoaderAppGuid, &LinuxLoaderDevicePath);\r
109 if (EFI_ERROR (Status)) {\r
110 Print (L"Couldn't Boot Linux: %d\n", Status);\r
111 return EFI_DEVICE_ERROR;\r
112 }\r
113\r
114 KernelDevicePathTxt = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath, FALSE, FALSE);\r
115 if (KernelDevicePathTxt == NULL) {\r
116 return EFI_OUT_OF_RESOURCES;\r
117 }\r
118\r
119 RamdiskDevicePathTxt = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *) RamdiskDevicePath, FALSE, FALSE);\r
120 if (RamdiskDevicePathTxt == NULL) {\r
121 return EFI_OUT_OF_RESOURCES;\r
122 }\r
123\r
124 // Initialize Legacy Linux loader command line\r
125 LoadOptions = CatSPrint (NULL, LINUX_LOADER_COMMAND_LINE, KernelDevicePathTxt, RamdiskDevicePathTxt, KernelArgs);\r
126 if (LoadOptions == NULL) {\r
127 return EFI_OUT_OF_RESOURCES;\r
128 }\r
129\r
130 Status = BdsStartEfiApplication (gImageHandle, LinuxLoaderDevicePath, StrSize (LoadOptions), LoadOptions);\r
131 if (EFI_ERROR (Status)) {\r
132 DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r
133 return EFI_DEVICE_ERROR;\r
134 }\r
135\r
136 if (RamdiskDevicePath) {\r
137 FreePool (RamdiskDevicePathTxt);\r
138 FreePool (RamdiskDevicePath);\r
139 }\r
140\r
141 FreePool (KernelDevicePathTxt);\r
142\r
143 // If we got here we do a confused face because BootLinuxFdt returned,\r
144 // reporting success.\r
145 DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r
146 return EFI_SUCCESS;\r
147}\r