]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Application/LinuxLoader/LinuxLoader.c
ArmPkg/LinuxLoader: eliminate calls to deprecated string functions
[mirror_edk2.git] / ArmPkg / Application / LinuxLoader / LinuxLoader.c
CommitLineData
23b01c83
RC
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
38EFI_STATUS\r
39EFIAPI\r
40LinuxLoaderEntryPoint (\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
9fbbbd12 64 UINTN Length;\r
23b01c83
RC
65\r
66 Status = gBS->LocateProtocol (\r
67 &gEfiDevicePathFromTextProtocolGuid,\r
68 NULL,\r
69 (VOID **)&EfiDevicePathFromTextProtocol\r
70 );\r
71 if (EFI_ERROR (Status)) {\r
72 return EFI_NOT_FOUND;\r
73 }\r
74\r
75 //\r
76 // Register the strings for the user interface in the HII Database.\r
77 // This shows the way to the multi-language support, even if\r
78 // only the English language is actually supported. The strings to register\r
79 // are stored in the "LinuxLoaderStrings[]" array. This array is\r
80 // built by the building process from the "*.uni" file associated to\r
81 // the present application (cf. LinuxLoader.inf). Examine the Build\r
82 // folder of the application and you will find the array defined in the\r
83 // LinuxLoaderStrDefs.h file.\r
84 //\r
85 mLinuxLoaderHiiHandle = HiiAddPackages (\r
86 &mLinuxLoaderHiiGuid,\r
87 ImageHandle,\r
88 LinuxLoaderStrings,\r
89 NULL\r
90 );\r
91 if (mLinuxLoaderHiiHandle == NULL) {\r
92 return EFI_NOT_FOUND;\r
93 }\r
94\r
95 Status = gBS->HandleProtocol (\r
96 ImageHandle,\r
97 &gEfiShellParametersProtocolGuid,\r
98 (VOID**)&ShellParameters\r
99 );\r
100\r
101 KernelDevicePath = NULL;\r
102 FdtDevicePath = NULL;\r
103 InitrdDevicePath = NULL;\r
104 AsciiLinuxCommandLine = NULL;\r
105\r
106 //\r
107 // Call the proper function to handle the command line\r
108 // depending on whether the application has been called\r
109 // from the Shell or not.\r
110 //\r
111\r
112 if (!EFI_ERROR (Status)) {\r
113 KernelTextDevicePath = NULL;\r
114 FdtTextDevicePath = NULL;\r
115 InitrdTextDevicePath = NULL;\r
116\r
117 Status = ProcessShellParameters (\r
118 &KernelPath, &FdtPath, &InitrdPath, &LinuxCommandLine, &AtagMachineType\r
119 );\r
120 if (EFI_ERROR (Status)) {\r
121 goto Error;\r
122 }\r
123\r
124 KernelDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (KernelPath);\r
125 if (KernelDevicePath != NULL) {\r
126 FreePool (KernelPath);\r
127 } else {\r
128 KernelTextDevicePath = KernelPath;\r
129 }\r
130\r
131 if (FdtPath != NULL) {\r
132 FdtDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (FdtPath);\r
133 if (FdtDevicePath != NULL) {\r
134 FreePool (FdtPath);\r
135 } else {\r
136 FdtTextDevicePath = FdtPath;\r
137 }\r
138 }\r
139\r
140 if (InitrdPath != NULL) {\r
141 InitrdDevicePath = gEfiShellProtocol->GetDevicePathFromFilePath (InitrdPath);\r
142 if (InitrdDevicePath != NULL) {\r
143 FreePool (InitrdPath);\r
144 } else {\r
145 InitrdTextDevicePath = InitrdPath;\r
146 }\r
147 }\r
148\r
149 } else {\r
150 Status = ProcessAppCommandLine (\r
151 &KernelTextDevicePath, &FdtTextDevicePath,\r
152 &InitrdTextDevicePath, &LinuxCommandLine, &AtagMachineType\r
153 );\r
154 if (EFI_ERROR (Status)) {\r
155 goto Error;\r
156 }\r
157 }\r
158\r
159 Status = EFI_INVALID_PARAMETER;\r
160 if (KernelTextDevicePath != NULL) {\r
161 KernelDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r
162 KernelTextDevicePath\r
163 );\r
164 if (KernelDevicePath == NULL) {\r
165 goto Error;\r
166 }\r
167 }\r
168 if (FdtTextDevicePath != NULL) {\r
169 FdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r
170 FdtTextDevicePath\r
171 );\r
172 if (FdtDevicePath == NULL) {\r
173 goto Error;\r
174 }\r
175 }\r
176 if (InitrdTextDevicePath != NULL) {\r
177 InitrdDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (\r
178 InitrdTextDevicePath\r
179 );\r
180 if (InitrdDevicePath == NULL) {\r
181 goto Error;\r
182 }\r
183 }\r
184\r
185 if (LinuxCommandLine != NULL) {\r
9fbbbd12
AB
186 Length = StrLen (LinuxCommandLine) + 1;\r
187 AsciiLinuxCommandLine = AllocatePool (Length);\r
23b01c83
RC
188 if (AsciiLinuxCommandLine == NULL) {\r
189 Status = EFI_OUT_OF_RESOURCES;\r
190 goto Error;\r
191 }\r
9fbbbd12 192 UnicodeStrToAsciiStrS (LinuxCommandLine, AsciiLinuxCommandLine, Length);\r
23b01c83
RC
193 }\r
194\r
195 //\r
196 // Find Base of System Memory - we keep the lowest physical address\r
197 //\r
198 SystemMemoryBase = ~0;\r
199 GetSystemMemoryResources (&ResourceList);\r
200 ResourceLink = ResourceList.ForwardLink;\r
201 while (ResourceLink != NULL && ResourceLink != &ResourceList) {\r
202 Resource = (SYSTEM_MEMORY_RESOURCE*)ResourceLink;\r
203 if (Resource->PhysicalStart < SystemMemoryBase) {\r
204 SystemMemoryBase = Resource->PhysicalStart;\r
205 }\r
206 ResourceLink = ResourceLink->ForwardLink;\r
207 }\r
208\r
209 if (AtagMachineType != ARM_FDT_MACHINE_TYPE) {\r
210 Status = BootLinuxAtag (SystemMemoryBase, KernelDevicePath, InitrdDevicePath, AsciiLinuxCommandLine, AtagMachineType);\r
211 } else {\r
212 Status = BootLinuxFdt (SystemMemoryBase, KernelDevicePath, InitrdDevicePath, FdtDevicePath, AsciiLinuxCommandLine);\r
213 }\r
214\r
215Error:\r
216 if (KernelTextDevicePath != NULL) {\r
217 FreePool (KernelTextDevicePath);\r
218 }\r
219 if (FdtTextDevicePath != NULL) {\r
220 FreePool (FdtTextDevicePath);\r
221 }\r
222 if (InitrdTextDevicePath != NULL) {\r
223 FreePool (InitrdTextDevicePath);\r
224 }\r
225 if (LinuxCommandLine != NULL) {\r
226 FreePool (LinuxCommandLine);\r
227 }\r
228 if (KernelDevicePath != NULL) {\r
229 FreePool (KernelDevicePath);\r
230 }\r
231 if (FdtDevicePath != NULL) {\r
232 FreePool (FdtDevicePath);\r
233 }\r
234 if (InitrdDevicePath != NULL) {\r
235 FreePool (InitrdDevicePath);\r
236 }\r
237 if (AsciiLinuxCommandLine != NULL) {\r
238 FreePool (AsciiLinuxCommandLine);\r
239 }\r
240\r
241 if (EFI_ERROR (Status)) {\r
242 PrintHii (NULL, STRING_TOKEN (STR_ERROR), Status);\r
243 }\r
244\r
245 HiiRemovePackages (mLinuxLoaderHiiHandle);\r
246\r
247 return Status;\r
248}\r