]>
Commit | Line | Data |
---|---|---|
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 | |
fcf41edf | 18 | #include <Protocol/LoadedImage.h>\r |
f6755908 OM |
19 | \r |
20 | #include <Library/BdsLib.h>\r | |
21 | #include <Library/DevicePathLib.h>\r | |
bd9a5182 OM |
22 | #include <Library/UefiBootServicesTableLib.h>\r |
23 | #include <Library/UefiLib.h>\r | |
f6755908 | 24 | \r |
f6755908 OM |
25 | // Device Path representing an image in memory\r |
26 | #pragma pack(1)\r | |
27 | typedef struct {\r | |
28 | MEMMAP_DEVICE_PATH Node1;\r | |
29 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
30 | } MEMORY_DEVICE_PATH;\r | |
31 | #pragma pack()\r | |
32 | \r | |
33 | STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =\r | |
34 | {\r | |
35 | {\r | |
36 | {\r | |
37 | HARDWARE_DEVICE_PATH,\r | |
38 | HW_MEMMAP_DP,\r | |
39 | {\r | |
40 | (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r | |
41 | (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),\r | |
42 | },\r | |
43 | }, // Header\r | |
44 | 0, // StartingAddress (set at runtime)\r | |
45 | 0 // EndingAddress (set at runtime)\r | |
46 | }, // Node1\r | |
47 | {\r | |
48 | END_DEVICE_PATH_TYPE,\r | |
49 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
b0fdce95 | 50 | { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r |
f6755908 OM |
51 | } // End\r |
52 | };\r | |
53 | \r | |
fcf41edf AB |
54 | \r |
55 | /**\r | |
56 | Start an EFI Application from a Device Path\r | |
57 | \r | |
58 | @param ParentImageHandle Handle of the calling image\r | |
59 | @param DevicePath Location of the EFI Application\r | |
60 | \r | |
61 | @retval EFI_SUCCESS All drivers have been connected\r | |
62 | @retval EFI_NOT_FOUND The Linux kernel Device Path has not been found\r | |
63 | @retval EFI_OUT_OF_RESOURCES There is not enough resource memory to store the matching results.\r | |
64 | \r | |
65 | **/\r | |
66 | STATIC\r | |
67 | EFI_STATUS\r | |
68 | StartEfiApplication (\r | |
69 | IN EFI_HANDLE ParentImageHandle,\r | |
70 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
71 | IN UINTN LoadOptionsSize,\r | |
72 | IN VOID* LoadOptions\r | |
73 | )\r | |
74 | {\r | |
75 | EFI_STATUS Status;\r | |
76 | EFI_HANDLE ImageHandle;\r | |
77 | EFI_LOADED_IMAGE_PROTOCOL* LoadedImage;\r | |
78 | \r | |
79 | // Load the image from the device path with Boot Services function\r | |
80 | Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, NULL, 0,\r | |
81 | &ImageHandle);\r | |
82 | if (EFI_ERROR (Status)) {\r | |
83 | return Status;\r | |
84 | }\r | |
85 | \r | |
86 | // Passed LoadOptions to the EFI Application\r | |
87 | if (LoadOptionsSize != 0) {\r | |
88 | Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid,\r | |
89 | (VOID **) &LoadedImage);\r | |
90 | if (EFI_ERROR (Status)) {\r | |
91 | return Status;\r | |
92 | }\r | |
93 | \r | |
94 | LoadedImage->LoadOptionsSize = LoadOptionsSize;\r | |
95 | LoadedImage->LoadOptions = LoadOptions;\r | |
96 | }\r | |
97 | \r | |
98 | // Before calling the image, enable the Watchdog Timer for the 5 Minute period\r | |
99 | gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r | |
100 | // Start the image\r | |
101 | Status = gBS->StartImage (ImageHandle, NULL, NULL);\r | |
102 | // Clear the Watchdog Timer after the image returns\r | |
103 | gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r | |
104 | \r | |
105 | return Status;\r | |
106 | }\r | |
107 | \r | |
f6755908 OM |
108 | EFI_STATUS\r |
109 | BootAndroidBootImg (\r | |
110 | IN UINTN BufferSize,\r | |
111 | IN VOID *Buffer\r | |
112 | )\r | |
113 | {\r | |
f6755908 | 114 | EFI_STATUS Status;\r |
6e414300 | 115 | CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];\r |
f6755908 OM |
116 | VOID *Kernel;\r |
117 | UINTN KernelSize;\r | |
118 | VOID *Ramdisk;\r | |
119 | UINTN RamdiskSize;\r | |
120 | MEMORY_DEVICE_PATH KernelDevicePath;\r | |
34e0bcea | 121 | CHAR16 *LoadOptions, *NewLoadOptions;\r |
f6755908 OM |
122 | \r |
123 | Status = ParseAndroidBootImg (\r | |
124 | Buffer,\r | |
125 | &Kernel,\r | |
126 | &KernelSize,\r | |
127 | &Ramdisk,\r | |
128 | &RamdiskSize,\r | |
129 | KernelArgs\r | |
130 | );\r | |
131 | if (EFI_ERROR (Status)) {\r | |
132 | return Status;\r | |
133 | }\r | |
134 | \r | |
135 | KernelDevicePath = MemoryDevicePathTemplate;\r | |
136 | \r | |
137 | // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to\r | |
138 | // appease GCC.\r | |
139 | KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;\r | |
140 | KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;\r | |
141 | \r | |
34e0bcea AB |
142 | // Initialize Linux command line\r |
143 | LoadOptions = CatSPrint (NULL, L"%a", KernelArgs);\r | |
144 | if (LoadOptions == NULL) {\r | |
bd9a5182 OM |
145 | return EFI_OUT_OF_RESOURCES;\r |
146 | }\r | |
147 | \r | |
34e0bcea AB |
148 | if (RamdiskSize != 0) {\r |
149 | NewLoadOptions = CatSPrint (LoadOptions, L" initrd=0x%x,0x%x",\r | |
150 | (UINTN)Ramdisk, RamdiskSize);\r | |
151 | FreePool (LoadOptions);\r | |
152 | if (NewLoadOptions == NULL) {\r | |
153 | return EFI_OUT_OF_RESOURCES;\r | |
154 | }\r | |
155 | LoadOptions = NewLoadOptions;\r | |
bd9a5182 OM |
156 | }\r |
157 | \r | |
fcf41edf | 158 | Status = StartEfiApplication (gImageHandle,\r |
34e0bcea AB |
159 | (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,\r |
160 | StrSize (LoadOptions),\r | |
161 | LoadOptions);\r | |
f6755908 OM |
162 | if (EFI_ERROR (Status)) {\r |
163 | DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));\r | |
34e0bcea AB |
164 | Status = EFI_DEVICE_ERROR;\r |
165 | goto FreeLoadOptions;\r | |
f6755908 OM |
166 | }\r |
167 | \r | |
168 | // If we got here we do a confused face because BootLinuxFdt returned,\r | |
169 | // reporting success.\r | |
170 | DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));\r | |
171 | return EFI_SUCCESS;\r | |
34e0bcea AB |
172 | \r |
173 | FreeLoadOptions:\r | |
174 | FreePool (LoadOptions);\r | |
175 | return Status;\r | |
f6755908 | 176 | }\r |