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