]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/EblExternCmd/EntryPointGlue.c
EmbeddedPkg: Fix mispellings
[mirror_edk2.git] / EmbeddedPkg / EblExternCmd / EntryPointGlue.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Glue code that contains the EFI entry point and converts it to an EBL \r
3 ASCII Argc, Argv sytle entry point\r
4\r
5\r
60274cca
HT
6 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
7 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
2ef2b01e 8\r
60274cca 9 This program and the accompanying materials\r
2ef2b01e
A
10 are licensed and made available under the terms and conditions of the BSD License\r
11 which accompanies this distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17\r
18**/\r
19\r
7ca9e5a4 20#define CMD_SEPARATOR ';'\r
2ef2b01e
A
21#define MAX_ARGS 32\r
22\r
23EFI_STATUS\r
24EblMain (\r
25 IN UINTN Argc,\r
26 IN CHAR8 **Argv\r
27 );\r
28\r
29\r
30///\r
31/// EdkExternCmdEntry() & ParseArguments() convert the standard EFI entry point\r
32/// into Argc, Argv form that calls EblMain().\r
33///\r
34\r
35\r
36/**\r
37 Parse the CmdLine and break it up into Argc (arg count) and Argv (array of\r
7ca9e5a4 38 pointers to each argument). The Cmd buffer is altered and separators are\r
2ef2b01e
A
39 converted to string terminators. This allows Argv to point into CmdLine.\r
40 A CmdLine can support multiple commands. The next command in the command line\r
41 is returned if it exists.\r
42\r
43 @param CmdLine String to parse for a set of commands\r
44 @param CmdLineSize Size of CmdLine in bytes\r
45 @param Argc Returns the number of arguments in the CmdLine current command\r
46 @param Argv Argc pointers to each string in CmdLine\r
47\r
48 @return Next Command in the command line or NULL if non exists\r
49**/\r
50VOID\r
51ParseArguments (\r
52 IN CHAR8 *CmdLine,\r
53 IN UINTN CmdLineSize,\r
54 OUT UINTN *Argc,\r
55 OUT CHAR8 **Argv\r
56 )\r
57{\r
58 UINTN Arg;\r
59 CHAR8 *Char;\r
60 BOOLEAN LookingForArg;\r
61 BOOLEAN InQuote;\r
62 UINTN Index;\r
63\r
64 *Argc = 0;\r
65 if ((CmdLineSize == 0) || (AsciiStrLen (CmdLine) == 0)) {\r
66 // basic error checking failed on the arguments\r
67 return;\r
68 }\r
69\r
7ca9e5a4 70 // Walk a single command line. A CMD_SEPARATOR allows multiple commands on a single line\r
2ef2b01e
A
71 InQuote = FALSE;\r
72 LookingForArg = TRUE;\r
7ca9e5a4 73 for (Char = CmdLine, Arg = 0, Index = 0; *Char != '\0' && *Char != CMD_SEPARATOR; Char++, Index++) {\r
74 // Perform any text conversion here\r
2ef2b01e
A
75 if (*Char == '\t') {\r
76 // TAB to space\r
77 *Char = ' ';\r
78 }\r
79\r
80 if (LookingForArg) {\r
7ca9e5a4 81 // Look for the beginning of an Argv[] entry\r
2ef2b01e
A
82 if (*Char == '"') {\r
83 Argv[Arg++] = ++Char;\r
84 LookingForArg = FALSE;\r
85 InQuote = TRUE;\r
86 } else if (*Char != ' ') {\r
87 Argv[Arg++] = Char;\r
88 LookingForArg = FALSE;\r
89 } \r
90 } else {\r
91 // Looking for the terminator of an Argv[] entry\r
92 if ((InQuote && (*Char == '"')) || (!InQuote && (*Char == ' '))) {\r
93 *Char = '\0';\r
94 LookingForArg = TRUE;\r
95 }\r
96 }\r
97\r
98 if ((Arg >= MAX_ARGS) || (Index > CmdLineSize)) {\r
99 // Error check buffer and exit since it does not look valid\r
100 break;\r
101 }\r
102 }\r
103\r
104 *Argc = Arg;\r
105\r
7ca9e5a4 106 if (*Char == CMD_SEPARATOR) {\r
107 // Replace the command delimiter with null\r
2ef2b01e
A
108 *Char = '\0';\r
109 }\r
110\r
111 return;\r
112}\r
113 \r
114\r
115\r
116\r
117/**\r
118 Embedded Boot Loader (EBL) - A simple EFI command line application for embedded \r
7ca9e5a4 119 devices. PcdEmbeddedAutomaticBootCommand is a complied in command line that\r
120 gets executed automatically. The ; separator allows multiple commands\r
2ef2b01e
A
121 for each command line.\r
122\r
123 @param ImageHandle EFI ImageHandle for this application.\r
124 @param SystemTable EFI system table\r
125\r
7ca9e5a4 126 @return EFI status of the application\r
2ef2b01e
A
127\r
128**/\r
129EFI_STATUS\r
130EFIAPI\r
131EdkExternCmdEntry (\r
132 IN EFI_HANDLE ImageHandle,\r
133 IN EFI_SYSTEM_TABLE *SystemTable\r
134 ) \r
135{\r
136 EFI_STATUS Status;\r
137 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
138 UINTN Argc;\r
139 CHAR8 *Argv[MAX_ARGS];\r
140\r
141 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r
142 if (EFI_ERROR (Status)) {\r
143 Argc = 0;\r
144 } else {\r
145 // Looks like valid commands were passed in. \r
146 ParseArguments (ImageInfo->LoadOptions, ImageInfo->LoadOptionsSize, &Argc, Argv);\r
147 }\r
148 \r
149 return EblMain (Argc, Argv);\r
150}\r
151\r
152\r