]>
Commit | Line | Data |
---|---|---|
94b17fa1 | 1 | /** @file\r |
2 | This is a simple shell application\r | |
3 | \r | |
4 | This should be executed with "/Param2 Val1" and "/Param1" as the 2 command line options!\r | |
5 | \r | |
9b3bf083 | 6 | Copyright (c) 2008-2009, Intel Corporation \r |
94b17fa1 | 7 | All rights reserved. This program and the accompanying materials \r |
8 | are licensed and made available under the terms and conditions of the BSD License \r | |
9 | which accompanies this distribution. The full text of the license may be found at \r | |
10 | http://opensource.org/licenses/bsd-license.php \r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
18 | #include <Library/UefiApplicationEntryPoint.h>\r | |
19 | #include <Library/UefiLib.h>\r | |
20 | #include <Library/ShellLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Library/MemoryAllocationLib.h>\r | |
23 | \r | |
24 | SHELL_PARAM_ITEM ParamList[] = {\r | |
25 | {L"/Param1", TypeFlag},\r | |
26 | {L"/Param2", TypeValue},\r | |
125c2cf4 | 27 | {L"/Param3", TypeDoubleValue},\r |
28 | {L"/Param4", TypeMaxValue},\r | |
94b17fa1 | 29 | {NULL, TypeMax}};\r |
30 | \r | |
31 | /**\r | |
32 | as the real entry point for the application.\r | |
33 | \r | |
34 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
35 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
38 | @retval other Some error occurs when executing this entry point.\r | |
39 | \r | |
40 | **/\r | |
41 | EFI_STATUS\r | |
42 | EFIAPI\r | |
43 | UefiMain (\r | |
44 | IN EFI_HANDLE ImageHandle,\r | |
45 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
46 | )\r | |
47 | {\r | |
48 | EFI_FILE_HANDLE FileHandle;\r | |
49 | EFI_STATUS Status;\r | |
50 | CHAR16 FileName[100];\r | |
77882e26 | 51 | UINTN BufferSize;\r |
52 | UINT64 Position;\r | |
53 | UINT8 Buffer[200];\r | |
94b17fa1 | 54 | EFI_FILE_INFO *pFileInfo;\r |
55 | UINT64 Size;\r | |
56 | BOOLEAN NoFile;\r | |
d2b4564b | 57 | EFI_SHELL_FILE_INFO *pShellFileInfo;\r |
94b17fa1 | 58 | LIST_ENTRY *List;\r |
77882e26 | 59 | // CONST CHAR16 *Tester;\r |
94b17fa1 | 60 | \r |
61 | FileHandle = NULL;\r | |
62 | StrCpy(FileName, L"testfile.txt");\r | |
125c2cf4 | 63 | // Position = 0;\r |
94b17fa1 | 64 | pFileInfo = NULL;\r |
65 | Size = 0;\r | |
66 | NoFile = FALSE;\r | |
67 | pShellFileInfo = NULL;\r | |
68 | List = NULL;\r | |
69 | \r | |
125c2cf4 | 70 | // command line param functions\r |
71 | Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);\r | |
72 | // if you put an invalid parameter you SHOULD hit this assert.\r | |
73 | ASSERT_EFI_ERROR(Status);\r | |
74 | if (List) {\r | |
75 | ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);\r | |
76 | ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);\r | |
77 | ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);\r | |
78 | ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);\r | |
77882e26 | 79 | // Tester = ShellCommandLineGetValue(List, L"/Param3");\r |
80 | // Tester = ShellCommandLineGetValue(List, L"/Param4");\r | |
125c2cf4 | 81 | \r |
82 | ShellCommandLineFreeVarList(List);\r | |
83 | } else {\r | |
84 | Print(L"param checking skipped.\r\n");\r | |
85 | }\r | |
86 | \r | |
1e4506f2 | 87 | // return (EFI_SUCCESS);\r |
88 | \r | |
125c2cf4 | 89 | \r |
94b17fa1 | 90 | ASSERT(ShellGetExecutionBreakFlag() == FALSE);\r |
125c2cf4 | 91 | ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0);\r |
94b17fa1 | 92 | Print(L"execution break and get cur dir - pass\r\n");\r |
93 | \r | |
94 | ShellSetPageBreakMode(TRUE);\r | |
95 | \r | |
96 | Status = ShellOpenFileByName(FileName, \r | |
97 | &FileHandle, \r | |
98 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
99 | 0\r | |
100 | );\r | |
101 | ASSERT_EFI_ERROR(Status);\r | |
102 | \r | |
103 | BufferSize = StrSize(FileName);\r | |
104 | Status = ShellWriteFile(FileHandle, &BufferSize, FileName);\r | |
105 | ASSERT_EFI_ERROR(Status);\r | |
106 | Status = ShellGetFilePosition(FileHandle, &Position);\r | |
107 | ASSERT_EFI_ERROR(Status);\r | |
108 | ASSERT(Position == 0x1A);\r | |
109 | Status = ShellSetFilePosition(FileHandle, 0);\r | |
110 | ASSERT_EFI_ERROR(Status);\r | |
111 | BufferSize = sizeof(Buffer) * sizeof(Buffer[0]);\r | |
112 | Status = ShellReadFile(FileHandle, &BufferSize, Buffer);\r | |
113 | ASSERT_EFI_ERROR(Status);\r | |
114 | ASSERT(BufferSize == 0x1A);\r | |
115 | ASSERT(StrCmp((CHAR16*)Buffer, FileName) == 0);\r | |
116 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
117 | ASSERT(pFileInfo != NULL);\r | |
118 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
119 | ASSERT(pFileInfo->FileSize == 0x1A);\r | |
120 | FreePool(pFileInfo);\r | |
121 | pFileInfo = NULL;\r | |
122 | Status = ShellCloseFile(&FileHandle);\r | |
94b17fa1 | 123 | ASSERT_EFI_ERROR(Status);\r |
124 | Print(L"read, write, create, getinfo - pass\r\n");\r | |
125 | \r | |
126 | Status = ShellOpenFileByName(FileName, \r | |
127 | &FileHandle, \r | |
128 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
129 | 0\r | |
130 | );\r | |
131 | ASSERT_EFI_ERROR(Status);\r | |
132 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
133 | ASSERT(pFileInfo != NULL);\r | |
134 | pFileInfo->FileSize = 0x20;\r | |
135 | Status = ShellSetFileInfo(FileHandle, pFileInfo);\r | |
136 | FreePool(pFileInfo);\r | |
137 | pFileInfo = NULL; \r | |
138 | ASSERT_EFI_ERROR(Status);\r | |
139 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
140 | ASSERT(pFileInfo != NULL);\r | |
141 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
142 | ASSERT(pFileInfo->PhysicalSize == 0x20);\r | |
143 | ASSERT(pFileInfo->FileSize == 0x20);\r | |
144 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
145 | FreePool(pFileInfo);\r | |
146 | Status = ShellGetFileSize(FileHandle, &Size);\r | |
147 | ASSERT(Size == 0x20);\r | |
148 | ASSERT_EFI_ERROR(Status);\r | |
149 | Status = ShellCloseFile(&FileHandle);\r | |
94b17fa1 | 150 | ASSERT_EFI_ERROR(Status);\r |
151 | Print(L"setinfo and change size, getsize - pass\r\n");\r | |
152 | \r | |
153 | Status = ShellOpenFileByName(FileName, \r | |
154 | &FileHandle, \r | |
155 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
156 | 0\r | |
157 | );\r | |
158 | ASSERT_EFI_ERROR(Status);\r | |
159 | \r | |
160 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
161 | ASSERT(pFileInfo != NULL);\r | |
162 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
163 | ASSERT(pFileInfo->PhysicalSize == 0x20);\r | |
164 | ASSERT(pFileInfo->FileSize == 0x20);\r | |
165 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
166 | FreePool(pFileInfo);\r | |
167 | pFileInfo = NULL; \r | |
168 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 169 | ASSERT_EFI_ERROR(Status);\r |
170 | Print(L"reopen file - pass\r\n");\r | |
171 | \r | |
172 | Status = ShellOpenFileByName(FileName, \r | |
173 | &FileHandle, \r | |
174 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
175 | 0\r | |
176 | );\r | |
177 | ASSERT_EFI_ERROR(Status);\r | |
178 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
179 | ASSERT(pFileInfo != NULL);\r | |
180 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
181 | ASSERT(pFileInfo->PhysicalSize == 0x0);\r | |
182 | ASSERT(pFileInfo->FileSize == 0x0);\r | |
183 | ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);\r | |
184 | FreePool(pFileInfo);\r | |
185 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 186 | ASSERT_EFI_ERROR(Status);\r |
187 | Print(L"size of empty - pass\r\n");\r | |
188 | \r | |
189 | Status = ShellOpenFileByName(FileName, \r | |
190 | &FileHandle, \r | |
191 | EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
192 | 0\r | |
193 | );\r | |
194 | ASSERT(Status == EFI_NOT_FOUND);\r | |
195 | ASSERT(FileHandle == NULL);\r | |
196 | \r | |
197 | Status = ShellCreateDirectory(FileName, &FileHandle);\r | |
198 | ASSERT_EFI_ERROR(Status);\r | |
199 | ASSERT(FileHandle != NULL);\r | |
200 | pFileInfo = ShellGetFileInfo(FileHandle);\r | |
201 | ASSERT(pFileInfo != NULL);\r | |
202 | ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);\r | |
203 | ASSERT(pFileInfo->Attribute&EFI_FILE_DIRECTORY);\r | |
204 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 205 | ASSERT_EFI_ERROR(Status);\r |
206 | Print(L"Directory create - pass\r\n");\r | |
207 | \r | |
208 | // FindFirst and FindNext\r | |
209 | StrCpy(FileName, L"testDir");\r | |
210 | Status = ShellCreateDirectory(FileName, &FileHandle);\r | |
211 | Status = ShellCloseFile(&FileHandle);\r | |
212 | StrCat(FileName, L"\\File.txt");\r | |
213 | Status = ShellOpenFileByName(FileName, \r | |
214 | &FileHandle, \r | |
215 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
216 | 0\r | |
217 | );\r | |
218 | ASSERT_EFI_ERROR(Status);\r | |
219 | Status = ShellCloseFile(&FileHandle);\r | |
220 | StrCpy(FileName, L"testDir");\r | |
221 | Status = ShellOpenFileByName(FileName, \r | |
222 | &FileHandle, \r | |
223 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
224 | 0\r | |
225 | );\r | |
226 | ASSERT_EFI_ERROR(Status);\r | |
d2b4564b | 227 | Status = ShellFindFirstFile(FileHandle, &pFileInfo);\r |
94b17fa1 | 228 | ASSERT_EFI_ERROR(Status);\r |
229 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
230 | ASSERT_EFI_ERROR(Status);\r | |
231 | ASSERT(NoFile == FALSE);\r | |
232 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
233 | ASSERT_EFI_ERROR(Status);\r | |
234 | ASSERT(NoFile == FALSE);\r | |
235 | Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);\r | |
236 | ASSERT_EFI_ERROR(Status);\r | |
9b3bf083 | 237 | ///@todo - why is NoFile never set? limitation of NT32 file system?\r |
94b17fa1 | 238 | Status = ShellDeleteFile(&FileHandle);\r |
94b17fa1 | 239 | ASSERT(Status == RETURN_WARN_DELETE_FAILURE);\r |
240 | Print(L"FindFirst - pass\r\n");\r | |
241 | Print(L"FindNext - Verify with real EFI system. Cant verify NoFile under NT32\r\n");\r | |
242 | \r | |
243 | // open and close meta arg\r | |
244 | Status = ShellOpenFileMetaArg(L"testDir\\*.*", EFI_FILE_MODE_READ, &pShellFileInfo);\r | |
245 | ASSERT_EFI_ERROR(Status);\r | |
246 | ASSERT(pShellFileInfo->Status == 0);\r | |
247 | ASSERT(StrCmp(pShellFileInfo->FileName, L"File.txt") == 0);\r | |
248 | ASSERT(pShellFileInfo->Handle);\r | |
249 | ASSERT(pShellFileInfo->Info);\r | |
250 | ASSERT(pShellFileInfo->Info->FileSize == 0);\r | |
251 | ASSERT(StrCmp(pShellFileInfo->Info->FileName, L"File.txt") == 0);\r | |
252 | ASSERT(pShellFileInfo->Info->Attribute == 0);\r | |
d2b4564b | 253 | \r |
94b17fa1 | 254 | Status = ShellCloseFileMetaArg(&pShellFileInfo);\r |
255 | ASSERT_EFI_ERROR(Status);\r | |
256 | Print(L"Open/Close Meta Arg - pass\r\n");\r | |
257 | \r | |
258 | // now delete that file and that directory\r | |
259 | StrCat(FileName, L"\\File.txt");\r | |
260 | Status = ShellOpenFileByName(FileName, \r | |
261 | &FileHandle, \r | |
262 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
263 | 0\r | |
264 | );\r | |
265 | ASSERT_EFI_ERROR(Status);\r | |
266 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 267 | StrCpy(FileName, L"testDir");\r |
268 | ASSERT_EFI_ERROR(Status);\r | |
269 | Status = ShellOpenFileByName(FileName, \r | |
270 | &FileHandle, \r | |
271 | EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, \r | |
272 | 0\r | |
273 | );\r | |
274 | Status = ShellDeleteFile(&FileHandle);\r | |
94b17fa1 | 275 | ASSERT_EFI_ERROR(Status);\r |
276 | \r | |
277 | // get environment variable\r | |
278 | // made for testing under nt32\r | |
125c2cf4 | 279 | ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);\r |
94b17fa1 | 280 | Print(L"ShellGetEnvironmentVariable - pass\r\n");\r |
281 | \r | |
282 | // set environment variable\r | |
283 | Status = ShellSetEnvironmentVariable(L"", L"", FALSE);\r | |
284 | ASSERT(Status == EFI_UNSUPPORTED);\r | |
285 | Print(L"ShellSetEnvironmentVariable - pass\r\n");\r | |
286 | \r | |
287 | // ShellExecute\r | |
288 | Status = ShellExecute(&ImageHandle, L"EmptyApplication.efi", TRUE, NULL, NULL);\r | |
289 | ASSERT_EFI_ERROR(Status);\r | |
290 | // the pass printout for this is performed by EmptyApplication\r | |
291 | Print(L"\r\n");\r | |
94b17fa1 | 292 | \r |
293 | // page break mode (done last so we can see the results)\r | |
294 | // we set this true at the begining of the program\r | |
295 | // this is enough lines to trigger the page...\r | |
296 | Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n");\r | |
297 | ShellSetPageBreakMode(FALSE);\r | |
298 | Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n");\r | |
299 | \r | |
300 | return EFI_SUCCESS;\r | |
301 | }\r | |
302 | \r | |
303 | \r | |
304 | /*\r | |
305 | done - ShellGetFileInfo\r | |
306 | done - ShellSetFileInfo\r | |
307 | done - ShellOpenFileByDevicePath\r | |
308 | done - ShellOpenFileByName\r | |
309 | done - ShellCreateDirectory\r | |
310 | done - ShellReadFile\r | |
311 | done - ShellWriteFile\r | |
312 | done - ShellCloseFile\r | |
313 | done - ShellDeleteFile\r | |
314 | done - ShellSetFilePosition\r | |
315 | done - ShellGetFilePosition\r | |
316 | ???? - ShellFlushFile\r | |
317 | done - ShellFindFirstFile\r | |
318 | done - ShellFindNextFile\r | |
319 | done - ShellGetFileSize\r | |
320 | done - ShellGetExecutionBreakFlag\r | |
321 | done - ShellGetEnvironmentVariable\r | |
322 | done - ShellSetEnvironmentVariable\r | |
323 | done - ShellExecute\r | |
324 | done - ShellGetCurrentDir\r | |
325 | done - ShellSetPageBreakMode\r | |
326 | done - ShellOpenFileMetaArg\r | |
327 | done - ShellCloseFileMetaArg\r | |
328 | done - ShellCommandLineParse\r | |
329 | done - ShellCommandLineFreeVarList\r | |
330 | done - ShellCommandLineGetFlag\r | |
331 | done - ShellCommandLineGetValue\r | |
332 | done - ShellCommandLineGetRawValue\r | |
e9880e25 | 333 | */\r |