]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Ebl/Script.c
ArmPlatformPkg: remove EblCmdLib implementation
[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
60274cca
HT
4 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
50c6a4d2 6 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
2ef2b01e 7\r
60274cca 8 This program and the accompanying materials\r
2ef2b01e
A
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16 Module Name: EfiDevice.c\r
17\r
18**/\r
19\r
20#include "Ebl.h"\r
21\r
22\r
23/**\r
24 Execute the passed in file like a series of commands. The ; can be used on\r
3402aac7
RC
25 a single line to indicate multiple commands per line. The Ascii text file\r
26 can contain any number of lines. The following line termination forms are\r
2ef2b01e
A
27 supported:\r
28 LF : Unix, Mac OS X*, BeOS\r
29 CR+LF: MS-DOS*, Microsoft Windows*\r
7ca9e5a4 30 CR : Commodore, Apple II, and really Mac OS\r
3402aac7 31 LF+CR: for simplicity and completeness\r
2ef2b01e
A
32\r
33 Argv[0] - "script"\r
34 Argv[1] - Device Name:path for the file to load\r
35\r
36 script fv1:\script.txt\r
37\r
38 @param Argc Number of command arguments in Argv\r
3402aac7 39 @param Argv Array of strings that represent the parsed command line.\r
7ca9e5a4 40 Argv[0] is the command name\r
2ef2b01e
A
41\r
42 @return EFI_SUCCESS\r
43\r
44**/\r
45EFI_STATUS\r
50c6a4d2 46EFIAPI\r
2ef2b01e
A
47EblScriptCmd (\r
48 IN UINTN Argc,\r
49 IN CHAR8 **Argv\r
50 )\r
51{\r
52 EFI_STATUS Status;\r
53 EFI_OPEN_FILE *File;\r
54 VOID *Address;\r
55 UINTN Size;\r
56 CHAR8 *Ptr;\r
57 CHAR8 *ScanPtr;\r
58 UINTN CmdLineSize;\r
3402aac7
RC
59\r
60\r
2ef2b01e
A
61\r
62 if (Argc < 2) {\r
63 // file name required\r
64 return EFI_SUCCESS;\r
65 }\r
66\r
67 File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);\r
68 if (File == NULL) {\r
69 AsciiPrint (" %a is not a valid path\n", Argv[1]);\r
70 return EFI_SUCCESS;\r
71 }\r
72\r
73 Status = EfiReadAllocatePool (File, &Address, &Size);\r
74 if (!EFI_ERROR (Status)) {\r
75 // Loop through each line in the text file\r
76 for (Ptr = (CHAR8 *)Address; (Ptr < (((CHAR8 *)Address) + Size)) && !EFI_ERROR (Status); Ptr += CmdLineSize) {\r
77 for (CmdLineSize = 0, ScanPtr = Ptr; ; CmdLineSize++, ScanPtr++) {\r
78 // look for the end of the line\r
79 if ((*ScanPtr == EBL_CR) || (*ScanPtr == EBL_LF)) {\r
80 // convert to NULL as this is what input routine would do\r
81 *ScanPtr = 0;\r
82 if ((*(ScanPtr + 1) == EBL_CR) || (*(ScanPtr + 1) == EBL_LF)) {\r
83 // if its a set get the 2nd EOL char\r
84 CmdLineSize++;\r
85 *(ScanPtr + 1) = 0;\r
86 }\r
87 CmdLineSize++;\r
88 break;\r
89 }\r
3402aac7 90\r
2ef2b01e
A
91 }\r
92\r
93 Status = ProcessCmdLine (Ptr, CmdLineSize);\r
94 }\r
3402aac7 95\r
2ef2b01e
A
96 FreePool (Address);\r
97 }\r
3402aac7 98\r
2ef2b01e
A
99 EfiClose (File);\r
100 return Status;\r
101}\r
102\r
103\r
104\r
105GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mScriptTemplate[] = {\r
106 {\r
107 "script",\r
3402aac7 108 " device:path; load an ascii file and execute it like commands",\r
2ef2b01e
A
109 NULL,\r
110 EblScriptCmd\r
111 }\r
112};\r
113\r
114\r
115/**\r
116 Initialize the commands in this in this file\r
117**/\r
118\r
119VOID\r
120EblInitializeScriptCmd (\r
121 VOID\r
122 )\r
123{\r
124 if (FeaturePcdGet (PcdEmbeddedScriptCmd)) {\r
125 EblAddCommands (mScriptTemplate, sizeof (mScriptTemplate)/sizeof (EBL_COMMAND_TABLE));\r
126 }\r
127}\r
128\r