]>
Commit | Line | Data |
---|---|---|
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 "LinuxLoader.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Internal variables\r | |
19 | //\r | |
20 | \r | |
21 | CONST EFI_GUID mLinuxLoaderHiiGuid = {\r | |
22 | 0xd5d16edc, 0x35c5, 0x4866,\r | |
23 | {0xbd, 0xe5, 0x2b, 0x64, 0xa2, 0x26, 0x55, 0x6e}\r | |
24 | };\r | |
25 | EFI_HANDLE mLinuxLoaderHiiHandle;\r | |
26 | \r | |
27 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
28 | {L"-f", TypeValue},\r | |
29 | {L"-d", TypeValue},\r | |
30 | {L"-c", TypeValue},\r | |
31 | {L"-a", TypeValue},\r | |
32 | {NULL , TypeMax }\r | |
33 | };\r | |
34 | \r | |
35 | /**\r | |
36 | Print a string given the "HII Id" of the format string and a list of\r | |
37 | arguments.\r | |
38 | \r | |
39 | @param[in] Language The language of the string to retrieve. If\r | |
40 | this parameter is NULL, then the current\r | |
41 | platform language is used.\r | |
42 | @param[in] HiiFormatStringId The format string Id for getting from Hii.\r | |
43 | @param[in] ... The variable argument list.\r | |
44 | \r | |
45 | @retval EFI_SUCCESS The printing was successful.\r | |
46 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
47 | \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | PrintHii (\r | |
51 | IN CONST CHAR8 *Language OPTIONAL,\r | |
52 | IN CONST EFI_STRING_ID HiiFormatStringId,\r | |
53 | ...\r | |
54 | )\r | |
55 | {\r | |
56 | VA_LIST Marker;\r | |
57 | CHAR16 *HiiFormatString;\r | |
58 | CHAR16 Buffer[MAX_MSG_LEN];\r | |
59 | \r | |
60 | VA_START (Marker, HiiFormatStringId);\r | |
61 | \r | |
62 | HiiFormatString = HiiGetString (mLinuxLoaderHiiHandle, HiiFormatStringId, Language);\r | |
63 | if (HiiFormatString != NULL) {\r | |
64 | UnicodeVSPrint (Buffer, sizeof (Buffer), HiiFormatString, Marker);\r | |
65 | Print (L"%s", Buffer);\r | |
66 | FreePool (HiiFormatString);\r | |
67 | } else {\r | |
68 | ASSERT (FALSE);\r | |
69 | return EFI_OUT_OF_RESOURCES;\r | |
70 | }\r | |
71 | \r | |
72 | VA_END (Marker);\r | |
73 | \r | |
74 | return EFI_SUCCESS;\r | |
75 | }\r | |
76 | \r | |
77 | /**\r | |
78 | Print the help.\r | |
79 | \r | |
80 | @param[in] Language The language of the string to retrieve. If this\r | |
81 | parameter is NULL, then the current platform\r | |
82 | language is used.\r | |
83 | **/\r | |
84 | VOID\r | |
85 | PrintHelp (\r | |
86 | IN CONST CHAR8 *Language OPTIONAL\r | |
87 | )\r | |
88 | {\r | |
89 | CHAR16 *Help;\r | |
90 | CHAR16 *Walker;\r | |
91 | CHAR16 *LineEnd;\r | |
92 | \r | |
93 | //\r | |
94 | // Print the help line by line as it is too big to be printed at once.\r | |
95 | //\r | |
96 | \r | |
97 | Help = HiiGetString (mLinuxLoaderHiiHandle, STRING_TOKEN (STR_HELP), Language);\r | |
98 | if (Help != NULL) {\r | |
99 | Walker = Help;\r | |
100 | while (*Walker != L'\0') {\r | |
101 | LineEnd = StrStr (Walker, L"\r\n");\r | |
102 | if (LineEnd != NULL) {\r | |
103 | *LineEnd = L'\0';\r | |
104 | }\r | |
105 | Print (L"%s\r\n", Walker);\r | |
106 | if (LineEnd == NULL) {\r | |
107 | break;\r | |
108 | }\r | |
109 | Walker = LineEnd + 2;\r | |
110 | }\r | |
111 | FreePool (Help);\r | |
112 | }\r | |
113 | \r | |
114 | }\r | |
115 | \r | |
116 | /**\r | |
117 | Process the Shell parameters in the case the application has been called\r | |
118 | from the EFI Shell.\r | |
119 | \r | |
120 | @param[out] KernelPath A pointer to the buffer where the path\r | |
121 | to the Linux kernel (EFI Shell file path\r | |
122 | or device path is stored. The address of\r | |
123 | the buffer is NULL in case of an error.\r | |
124 | Otherwise, the returned address is the\r | |
125 | address of a buffer allocated with\r | |
126 | a call to AllocatePool() that has to be\r | |
127 | freed by the caller.\r | |
128 | @param[out] FdtPath A pointer to the buffer where the path\r | |
129 | to the FDT (EFI Shell file path or\r | |
130 | device path) is stored. The address of\r | |
131 | the buffer is NULL in case of an error or\r | |
132 | if the path to the FDT is not defined.\r | |
133 | Otherwise, the returned address is the\r | |
134 | address of a buffer allocated with a call\r | |
135 | to AllocatePool() that has to be freed by\r | |
136 | the caller.\r | |
137 | @param[out] InitrdPath A pointer to the buffer where the path\r | |
138 | (EFI Shell file path or device path)\r | |
139 | to the RAM root file system is stored.\r | |
140 | The address of the buffer is NULL in case\r | |
141 | of an error or if the path to the RAM root\r | |
142 | file system is not defined. Otherwise, the\r | |
143 | returned address is the address of a\r | |
144 | buffer allocated with a call to\r | |
145 | AllocatePool() that has to be freed by\r | |
146 | the caller.\r | |
147 | @param[out] LinuxCommandLine A pointer to the buffer where the Linux\r | |
148 | kernel command line is stored. The address\r | |
149 | of the buffer is NULL in case of an error\r | |
150 | or if the Linux command line is not\r | |
151 | defined. Otherwise, the returned address\r | |
152 | is the address of a buffer allocated with\r | |
153 | a call to AllocatePool() that has to be\r | |
154 | freed by the caller.\r | |
155 | @param[out] AtagMachineType Value of the ARM Machine Type\r | |
156 | \r | |
157 | @retval EFI_SUCCESS The processing was successfull.\r | |
158 | @retval EFI_ABORTED The initialisation of the Shell Library failed.\r | |
159 | @retval EFI_NOT_FOUND Path to the Linux kernel not found.\r | |
160 | @retval EFI_INVALID_PARAMETER At least one parameter is not valid or there is a\r | |
161 | conflict between two parameters.\r | |
162 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
163 | \r | |
164 | **/\r | |
165 | EFI_STATUS\r | |
166 | ProcessShellParameters (\r | |
167 | OUT CHAR16 **KernelPath,\r | |
168 | OUT CHAR16 **FdtPath,\r | |
169 | OUT CHAR16 **InitrdPath,\r | |
170 | OUT CHAR16 **LinuxCommandLine,\r | |
171 | OUT UINTN *AtagMachineType\r | |
172 | )\r | |
173 | {\r | |
174 | EFI_STATUS Status;\r | |
175 | LIST_ENTRY *CheckPackage;\r | |
176 | CHAR16 *ProblemParam;\r | |
177 | CONST CHAR16 *FlagValue;\r | |
178 | CONST CHAR16 *ParameterValue;\r | |
179 | UINTN LinuxCommandLineLen;\r | |
180 | \r | |
181 | \r | |
182 | *KernelPath = NULL;\r | |
183 | *FdtPath = NULL;\r | |
184 | *InitrdPath = NULL;\r | |
185 | *LinuxCommandLine = NULL;\r | |
186 | *AtagMachineType = ARM_FDT_MACHINE_TYPE;\r | |
187 | \r | |
188 | //\r | |
189 | // Initialise the Shell Library as we are going to use it.\r | |
190 | // Assert that the return code is EFI_SUCCESS as it should.\r | |
191 | // To anticipate any change is the codes returned by\r | |
192 | // ShellInitialize(), leave in case of error.\r | |
193 | //\r | |
194 | Status = ShellInitialize ();\r | |
195 | if (EFI_ERROR (Status)) {\r | |
196 | ASSERT_EFI_ERROR (Status);\r | |
197 | return EFI_ABORTED;\r | |
198 | }\r | |
199 | \r | |
200 | Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE);\r | |
201 | if (EFI_ERROR (Status)) {\r | |
202 | if ((Status == EFI_VOLUME_CORRUPTED) &&\r | |
203 | (ProblemParam != NULL) ) {\r | |
204 | PrintHii (\r | |
205 | NULL, STRING_TOKEN (STR_SHELL_INVALID_PARAMETER), ProblemParam\r | |
206 | );\r | |
207 | FreePool (ProblemParam);\r | |
208 | } else {\r | |
209 | ASSERT (FALSE);\r | |
210 | }\r | |
211 | goto Error;\r | |
212 | }\r | |
213 | \r | |
214 | Status = EFI_INVALID_PARAMETER;\r | |
215 | if (ShellCommandLineGetCount (CheckPackage) != 2) {\r | |
216 | PrintHelp (NULL);\r | |
217 | goto Error;\r | |
218 | }\r | |
219 | \r | |
220 | Status = EFI_OUT_OF_RESOURCES;\r | |
221 | \r | |
222 | FlagValue = ShellCommandLineGetValue (CheckPackage, L"-a");\r | |
223 | if (FlagValue != NULL) {\r | |
224 | if (ShellCommandLineGetFlag (CheckPackage, L"-d")) {\r | |
225 | PrintHii (NULL, STRING_TOKEN (STR_ATAG_FDT_CONFLICT));\r | |
226 | goto Error;\r | |
227 | }\r | |
228 | *AtagMachineType = StrDecimalToUintn (FlagValue);\r | |
229 | }\r | |
230 | \r | |
231 | ParameterValue = ShellCommandLineGetRawValue (CheckPackage, 1);\r | |
232 | *KernelPath = AllocateCopyPool (StrSize (ParameterValue), ParameterValue);\r | |
233 | if (*KernelPath == NULL) {\r | |
234 | goto Error;\r | |
235 | }\r | |
236 | \r | |
237 | FlagValue = ShellCommandLineGetValue (CheckPackage, L"-d");\r | |
238 | if (FlagValue != NULL) {\r | |
239 | *FdtPath = AllocateCopyPool (StrSize (FlagValue), FlagValue);\r | |
240 | if (*FdtPath == NULL) {\r | |
241 | goto Error;\r | |
242 | }\r | |
243 | }\r | |
244 | \r | |
245 | FlagValue = ShellCommandLineGetValue (CheckPackage, L"-f");\r | |
246 | if (FlagValue != NULL) {\r | |
247 | *InitrdPath = AllocateCopyPool (StrSize (FlagValue), FlagValue);\r | |
248 | if (*InitrdPath == NULL) {\r | |
249 | goto Error;\r | |
250 | }\r | |
251 | }\r | |
252 | \r | |
253 | FlagValue = ShellCommandLineGetValue (CheckPackage, L"-c");\r | |
254 | if (FlagValue != NULL) {\r | |
255 | LinuxCommandLineLen = StrLen (FlagValue);\r | |
256 | if ((LinuxCommandLineLen != 0) &&\r | |
257 | (FlagValue[0] == L'"' ) &&\r | |
258 | (FlagValue[LinuxCommandLineLen - 1] == L'"')) {\r | |
259 | FlagValue++;\r | |
260 | LinuxCommandLineLen -= 2;\r | |
261 | }\r | |
262 | \r | |
263 | *LinuxCommandLine = AllocateCopyPool (\r | |
264 | (LinuxCommandLineLen + 1) * sizeof (CHAR16),\r | |
265 | FlagValue\r | |
266 | );\r | |
267 | if (*LinuxCommandLine == NULL) {\r | |
268 | goto Error;\r | |
269 | }\r | |
270 | (*LinuxCommandLine)[LinuxCommandLineLen] = L'\0';\r | |
271 | }\r | |
272 | \r | |
273 | Status = EFI_SUCCESS;\r | |
274 | \r | |
275 | Error:\r | |
276 | ShellCommandLineFreeVarList (CheckPackage);\r | |
277 | \r | |
278 | if (EFI_ERROR (Status)) {\r | |
279 | if (*KernelPath != NULL) {\r | |
280 | FreePool (*KernelPath);\r | |
281 | *KernelPath = NULL;\r | |
282 | }\r | |
283 | if (*FdtPath != NULL) {\r | |
284 | FreePool (*FdtPath);\r | |
285 | *FdtPath = NULL;\r | |
286 | }\r | |
287 | if (*InitrdPath != NULL) {\r | |
288 | FreePool (*InitrdPath);\r | |
289 | *InitrdPath = NULL;\r | |
290 | }\r | |
291 | if (*LinuxCommandLine != NULL) {\r | |
292 | FreePool (*LinuxCommandLine);\r | |
293 | *LinuxCommandLine = NULL;\r | |
294 | }\r | |
295 | }\r | |
296 | \r | |
297 | return Status;\r | |
298 | }\r |