]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Ebl/Script.c
Change UI for dir of FV to make it less confusing.
[mirror_edk2.git] / EmbeddedPkg / Ebl / Script.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Script command allows the execution of commands from a text file\r
3\r
4 Copyright (c) 2007, Intel Corporation<BR>\r
5 Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
6\r
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 Module Name: EfiDevice.c\r
16\r
17**/\r
18\r
19#include "Ebl.h"\r
20\r
21\r
22/**\r
23 Execute the passed in file like a series of commands. The ; can be used on\r
24 a single line to indicate multiple commands per line. The Ascii text file \r
25 can contain any number of lines. The following line termination forms are \r
26 supported:\r
27 LF : Unix, Mac OS X*, BeOS\r
28 CR+LF: MS-DOS*, Microsoft Windows*\r
29 CR : Commodore, Apple II, and realy Mac OS\r
30 LF+CR: for simplicity and completeness \r
31\r
32 Argv[0] - "script"\r
33 Argv[1] - Device Name:path for the file to load\r
34\r
35 script fv1:\script.txt\r
36\r
37 @param Argc Number of command arguments in Argv\r
38 @param Argv Array of strings that represent the parsed command line. \r
39 Argv[0] is the comamnd name\r
40\r
41 @return EFI_SUCCESS\r
42\r
43**/\r
44EFI_STATUS\r
45EblScriptCmd (\r
46 IN UINTN Argc,\r
47 IN CHAR8 **Argv\r
48 )\r
49{\r
50 EFI_STATUS Status;\r
51 EFI_OPEN_FILE *File;\r
52 VOID *Address;\r
53 UINTN Size;\r
54 CHAR8 *Ptr;\r
55 CHAR8 *ScanPtr;\r
56 UINTN CmdLineSize;\r
57 \r
58 \r
59\r
60 if (Argc < 2) {\r
61 // file name required\r
62 return EFI_SUCCESS;\r
63 }\r
64\r
65 File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);\r
66 if (File == NULL) {\r
67 AsciiPrint (" %a is not a valid path\n", Argv[1]);\r
68 return EFI_SUCCESS;\r
69 }\r
70\r
71 Status = EfiReadAllocatePool (File, &Address, &Size);\r
72 if (!EFI_ERROR (Status)) {\r
73 // Loop through each line in the text file\r
74 for (Ptr = (CHAR8 *)Address; (Ptr < (((CHAR8 *)Address) + Size)) && !EFI_ERROR (Status); Ptr += CmdLineSize) {\r
75 for (CmdLineSize = 0, ScanPtr = Ptr; ; CmdLineSize++, ScanPtr++) {\r
76 // look for the end of the line\r
77 if ((*ScanPtr == EBL_CR) || (*ScanPtr == EBL_LF)) {\r
78 // convert to NULL as this is what input routine would do\r
79 *ScanPtr = 0;\r
80 if ((*(ScanPtr + 1) == EBL_CR) || (*(ScanPtr + 1) == EBL_LF)) {\r
81 // if its a set get the 2nd EOL char\r
82 CmdLineSize++;\r
83 *(ScanPtr + 1) = 0;\r
84 }\r
85 CmdLineSize++;\r
86 break;\r
87 }\r
88 \r
89 }\r
90\r
91 Status = ProcessCmdLine (Ptr, CmdLineSize);\r
92 }\r
93 \r
94 FreePool (Address);\r
95 }\r
96 \r
97 EfiClose (File);\r
98 return Status;\r
99}\r
100\r
101\r
102\r
103GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mScriptTemplate[] = {\r
104 {\r
105 "script",\r
106 " device:path; load an ascii file and execute it like commands", \r
107 NULL,\r
108 EblScriptCmd\r
109 }\r
110};\r
111\r
112\r
113/**\r
114 Initialize the commands in this in this file\r
115**/\r
116\r
117VOID\r
118EblInitializeScriptCmd (\r
119 VOID\r
120 )\r
121{\r
122 if (FeaturePcdGet (PcdEmbeddedScriptCmd)) {\r
123 EblAddCommands (mScriptTemplate, sizeof (mScriptTemplate)/sizeof (EBL_COMMAND_TABLE));\r
124 }\r
125}\r
126\r