]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2015, ARM Limited. All rights reserved.\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 <Library/UefiApplicationEntryPoint.h>\r | |
16 | #include <Library/BaseMemoryLib.h>\r | |
17 | \r | |
18 | #include <Protocol/DevicePathFromText.h>\r | |
19 | \r | |
20 | #include "LinuxLoader.h"\r | |
21 | \r | |
22 | /**\r | |
23 | The user Entry Point for Application. The user code starts with this function\r | |
24 | as the real entry point for the application.\r | |
25 | \r | |
26 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
27 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
28 | \r | |
29 | @retval EFI_SUCCESS The entry point was executed successfully.\r | |
30 | @retval EFI_NOT_FOUND Protocol not found.\r | |
31 | @retval EFI_NOT_FOUND Path to the Linux kernel not found.\r | |
32 | @retval EFI_ABORTED The initialisation of the Shell Library failed.\r | |
33 | @retval EFI_INVALID_PARAMETER At least one parameter is not valid or there is a\r | |
34 | conflict between two parameters.\r | |
35 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
36 | \r | |
37 | **/\r | |
38 | EFI_STATUS\r | |
39 | EFIAPI\r | |
40 | LinuxLoaderEntryPoint (\r | |
41 | IN EFI_HANDLE ImageHandle,\r | |
42 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
43 | )\r | |
44 | {\r | |
45 | EFI_STATUS Status;\r | |
46 | EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;\r | |
47 | EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;\r | |
48 | CHAR16 *KernelPath;\r | |
49 | CHAR16 *FdtPath;\r | |
50 | CHAR16 *InitrdPath;\r | |
51 | CHAR16 *KernelTextDevicePath;\r | |
52 | CHAR16 *FdtTextDevicePath;\r | |
53 | CHAR16 *InitrdTextDevicePath;\r | |
54 | CHAR16 *LinuxCommandLine;\r | |
55 | UINTN AtagMachineType;\r | |
56 | EFI_DEVICE_PATH *KernelDevicePath;\r | |
57 | EFI_DEVICE_PATH *FdtDevicePath;\r | |
58 | EFI_DEVICE_PATH *InitrdDevicePath;\r | |
59 | CHAR8 *AsciiLinuxCommandLine;\r | |
60 | LIST_ENTRY ResourceList;\r | |
61 | LIST_ENTRY *ResourceLink;\r | |
62 | SYSTEM_MEMORY_RESOURCE *Resource;\r | |
63 | EFI_PHYSICAL_ADDRESS SystemMemoryBase;\r | |
64 | \r | |
65 | Status = gBS->LocateProtocol (\r | |
66 | &gEfiDevicePathFromTextProtocolGuid,\r | |
67 | NULL,\r | |
68 | (VOID **)&EfiDevicePathFromTextProtocol\r | |
69 | );\r | |
70 | if (EFI_ERROR (Status)) {\r | |
71 | return EFI_NOT_FOUND;\r | |
72 | }\r | |
73 | \r | |
74 | //\r | |
75 | // Register the strings for the user interface in the HII Database.\r | |
76 | // This shows the way to the multi-language support, even if\r | |
77 | // only the English language is actually supported. The strings to register\r | |
78 | // are stored in the "LinuxLoaderStrings[]" array. This array is\r | |
79 | // built by the building process from the "*.uni" file associated to\r | |
80 | // the present application (cf. LinuxLoader.inf). Examine the Build\r | |
81 | // folder of the application and you will find the array defined in the\r | |
82 | // LinuxLoaderStrDefs.h file.\r | |
83 | //\r | |
84 | mLinuxLoaderHiiHandle = HiiAddPackages (\r | |
85 | &mLinuxLoaderHiiGuid,\r | |
86 | ImageHandle,\r | |
87 | LinuxLoaderStrings,\r | |
88 | NULL\r | |
89 | );\r | |
90 | if (mLinuxLoaderHiiHandle == NULL) {\r | |
91 | return EFI_NOT_FOUND;\r | |
92 | }\r | |
93 | \r | |
94 | Status = gBS->HandleProtocol (\r | |
95 | ImageHandle,\r | |
96 | &gEfiShellParametersProtocolGuid,\r | |
97 | (VOID**)&ShellParameters\r | |
98 | );\r | |
99 | \r | |
100 | KernelDevicePath = NULL;\r | |
101 | FdtDevicePath = NULL;\r | |
102 | InitrdDevicePath = NULL;\r | |
103 | AsciiLinuxCommandLine = NULL;\r | |
104 | \r | |
105 | //\r | |
106 | // Call the proper function to handle the command line\r | |
107 | // depending on whether the application has been called\r | |
108 | // from the Shell or not.\r | |
109 | //\r | |
110 | \r | |
111 | if (!EFI_ERROR (Status)) {\r | |
112 | KernelTextDevicePath = NULL;\r | |
113 | FdtTextDevicePath = NULL;\r | |
114 | InitrdTextDevicePath = NULL;\r | |
115 | \r | |
116 | Status = ProcessShellParameters (\r | |
117 | &KernelPath, &FdtPath, &InitrdPath, &LinuxCommandLine, &AtagMachineType\r | |
118 | );\r | |
119 | if (EFI_ERROR (Status)) {\r | |
120 | goto Error;\r | |
121 | }\r | |
122 | \r | |
123 | KernelDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (KernelPath);\r | |
124 | if (KernelDevicePath != NULL) {\r | |
125 | FreePool (KernelPath);\r | |
126 | } else {\r | |
127 | KernelTextDevicePath = KernelPath;\r | |
128 | }\r | |
129 | \r | |
130 | if (FdtPath != NULL) {\r | |
131 | FdtDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (FdtPath);\r | |
132 | if (FdtDevicePath != NULL) {\r | |
133 | FreePool (FdtPath);\r | |
134 | } else {\r | |
135 | FdtTextDevicePath = FdtPath;\r | |
136 | }\r | |
137 | }\r | |
138 | \r | |
139 | if (InitrdPath != NULL) {\r | |
140 | InitrdDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (InitrdPath);\r | |
141 | if (InitrdDevicePath != NULL) {\r | |
142 | FreePool (InitrdPath);\r | |
143 | } else {\r | |
144 | InitrdTextDevicePath = InitrdPath;\r | |
145 | }\r | |
146 | }\r | |
147 | \r | |
148 | } else {\r | |
149 | Status = ProcessAppCommandLine (\r | |
150 | &KernelTextDevicePath, &FdtTextDevicePath,\r | |
151 | &InitrdTextDevicePath, &LinuxCommandLine, &AtagMachineType\r | |
152 | );\r | |
153 | if (EFI_ERROR (Status)) {\r | |
154 | goto Error;\r | |
155 | }\r | |
156 | }\r | |
157 | \r | |
158 | Status = EFI_INVALID_PARAMETER;\r | |
159 | if (KernelTextDevicePath != NULL) {\r | |
160 | KernelDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r | |
161 | KernelTextDevicePath\r | |
162 | );\r | |
163 | if (KernelDevicePath == NULL) {\r | |
164 | goto Error;\r | |
165 | }\r | |
166 | }\r | |
167 | if (FdtTextDevicePath != NULL) {\r | |
168 | FdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r | |
169 | FdtTextDevicePath\r | |
170 | );\r | |
171 | if (FdtDevicePath == NULL) {\r | |
172 | goto Error;\r | |
173 | }\r | |
174 | }\r | |
175 | if (InitrdTextDevicePath != NULL) {\r | |
176 | InitrdDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r | |
177 | InitrdTextDevicePath\r | |
178 | );\r | |
179 | if (InitrdDevicePath == NULL) {\r | |
180 | goto Error;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
184 | if (LinuxCommandLine != NULL) {\r | |
185 | AsciiLinuxCommandLine = AllocatePool ((StrLen (LinuxCommandLine) + 1) * sizeof (CHAR8));\r | |
186 | if (AsciiLinuxCommandLine == NULL) {\r | |
187 | Status = EFI_OUT_OF_RESOURCES;\r | |
188 | goto Error;\r | |
189 | }\r | |
190 | UnicodeStrToAsciiStr (LinuxCommandLine, AsciiLinuxCommandLine);\r | |
191 | }\r | |
192 | \r | |
193 | //\r | |
194 | // Find Base of System Memory - we keep the lowest physical address\r | |
195 | //\r | |
196 | SystemMemoryBase = ~0;\r | |
197 | GetSystemMemoryResources (&ResourceList);\r | |
198 | ResourceLink = ResourceList.ForwardLink;\r | |
199 | while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r | |
200 | Resource = (SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r | |
201 | if (Resource->PhysicalStart < SystemMemoryBase) {\r | |
202 | SystemMemoryBase = Resource->PhysicalStart;\r | |
203 | }\r | |
204 | ResourceLink = ResourceLink->ForwardLink;\r | |
205 | }\r | |
206 | \r | |
207 | if (AtagMachineType != ARM_FDT_MACHINE_TYPE) {\r | |
208 | Status = BootLinuxAtag (SystemMemoryBase, KernelDevicePath, InitrdDevicePath, AsciiLinuxCommandLine, AtagMachineType);\r | |
209 | } else {\r | |
210 | Status = BootLinuxFdt (SystemMemoryBase, KernelDevicePath, InitrdDevicePath, FdtDevicePath, AsciiLinuxCommandLine);\r | |
211 | }\r | |
212 | \r | |
213 | Error:\r | |
214 | if (KernelTextDevicePath != NULL) {\r | |
215 | FreePool (KernelTextDevicePath);\r | |
216 | }\r | |
217 | if (FdtTextDevicePath != NULL) {\r | |
218 | FreePool (FdtTextDevicePath);\r | |
219 | }\r | |
220 | if (InitrdTextDevicePath != NULL) {\r | |
221 | FreePool (InitrdTextDevicePath);\r | |
222 | }\r | |
223 | if (LinuxCommandLine != NULL) {\r | |
224 | FreePool (LinuxCommandLine);\r | |
225 | }\r | |
226 | if (KernelDevicePath != NULL) {\r | |
227 | FreePool (KernelDevicePath);\r | |
228 | }\r | |
229 | if (FdtDevicePath != NULL) {\r | |
230 | FreePool (FdtDevicePath);\r | |
231 | }\r | |
232 | if (InitrdDevicePath != NULL) {\r | |
233 | FreePool (InitrdDevicePath);\r | |
234 | }\r | |
235 | if (AsciiLinuxCommandLine != NULL) {\r | |
236 | FreePool (AsciiLinuxCommandLine);\r | |
237 | }\r | |
238 | \r | |
239 | if (EFI_ERROR (Status)) {\r | |
240 | PrintHii (NULL, STRING_TOKEN (STR_ERROR), Status);\r | |
241 | }\r | |
242 | \r | |
243 | HiiRemovePackages (mLinuxLoaderHiiHandle);\r | |
244 | \r | |
245 | return Status;\r | |
246 | }\r |