]>
Commit | Line | Data |
---|---|---|
2ef2b01e | 1 | /** @file\r |
3402aac7 | 2 | Glue code that contains the EFI entry point and converts it to an EBL\r |
2ef2b01e A |
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 | |
11c20f4e | 20 | #include "Ebl.h"\r |
21 | \r | |
7ca9e5a4 | 22 | #define CMD_SEPARATOR ';'\r |
2ef2b01e A |
23 | #define MAX_ARGS 32\r |
24 | \r | |
25 | EFI_STATUS\r | |
26 | EblMain (\r | |
27 | IN UINTN Argc,\r | |
28 | IN CHAR8 **Argv\r | |
29 | );\r | |
30 | \r | |
31 | \r | |
32 | ///\r | |
33 | /// EdkExternCmdEntry() & ParseArguments() convert the standard EFI entry point\r | |
34 | /// into Argc, Argv form that calls EblMain().\r | |
35 | ///\r | |
36 | \r | |
37 | \r | |
38 | /**\r | |
39 | Parse the CmdLine and break it up into Argc (arg count) and Argv (array of\r | |
7ca9e5a4 | 40 | pointers to each argument). The Cmd buffer is altered and separators are\r |
2ef2b01e A |
41 | converted to string terminators. This allows Argv to point into CmdLine.\r |
42 | A CmdLine can support multiple commands. The next command in the command line\r | |
43 | is returned if it exists.\r | |
44 | \r | |
45 | @param CmdLine String to parse for a set of commands\r | |
46 | @param CmdLineSize Size of CmdLine in bytes\r | |
47 | @param Argc Returns the number of arguments in the CmdLine current command\r | |
48 | @param Argv Argc pointers to each string in CmdLine\r | |
49 | \r | |
50 | @return Next Command in the command line or NULL if non exists\r | |
51 | **/\r | |
52 | VOID\r | |
53 | ParseArguments (\r | |
54 | IN CHAR8 *CmdLine,\r | |
55 | IN UINTN CmdLineSize,\r | |
56 | OUT UINTN *Argc,\r | |
57 | OUT CHAR8 **Argv\r | |
58 | )\r | |
59 | {\r | |
60 | UINTN Arg;\r | |
61 | CHAR8 *Char;\r | |
62 | BOOLEAN LookingForArg;\r | |
63 | BOOLEAN InQuote;\r | |
64 | UINTN Index;\r | |
65 | \r | |
66 | *Argc = 0;\r | |
67 | if ((CmdLineSize == 0) || (AsciiStrLen (CmdLine) == 0)) {\r | |
68 | // basic error checking failed on the arguments\r | |
69 | return;\r | |
70 | }\r | |
71 | \r | |
7ca9e5a4 | 72 | // Walk a single command line. A CMD_SEPARATOR allows multiple commands on a single line\r |
2ef2b01e A |
73 | InQuote = FALSE;\r |
74 | LookingForArg = TRUE;\r | |
7ca9e5a4 | 75 | for (Char = CmdLine, Arg = 0, Index = 0; *Char != '\0' && *Char != CMD_SEPARATOR; Char++, Index++) {\r |
76 | // Perform any text conversion here\r | |
2ef2b01e A |
77 | if (*Char == '\t') {\r |
78 | // TAB to space\r | |
79 | *Char = ' ';\r | |
80 | }\r | |
81 | \r | |
82 | if (LookingForArg) {\r | |
7ca9e5a4 | 83 | // Look for the beginning of an Argv[] entry\r |
2ef2b01e A |
84 | if (*Char == '"') {\r |
85 | Argv[Arg++] = ++Char;\r | |
86 | LookingForArg = FALSE;\r | |
87 | InQuote = TRUE;\r | |
88 | } else if (*Char != ' ') {\r | |
89 | Argv[Arg++] = Char;\r | |
90 | LookingForArg = FALSE;\r | |
3402aac7 | 91 | }\r |
2ef2b01e A |
92 | } else {\r |
93 | // Looking for the terminator of an Argv[] entry\r | |
94 | if ((InQuote && (*Char == '"')) || (!InQuote && (*Char == ' '))) {\r | |
95 | *Char = '\0';\r | |
96 | LookingForArg = TRUE;\r | |
97 | }\r | |
98 | }\r | |
99 | \r | |
100 | if ((Arg >= MAX_ARGS) || (Index > CmdLineSize)) {\r | |
101 | // Error check buffer and exit since it does not look valid\r | |
102 | break;\r | |
103 | }\r | |
104 | }\r | |
105 | \r | |
106 | *Argc = Arg;\r | |
107 | \r | |
7ca9e5a4 | 108 | if (*Char == CMD_SEPARATOR) {\r |
109 | // Replace the command delimiter with null\r | |
2ef2b01e A |
110 | *Char = '\0';\r |
111 | }\r | |
112 | \r | |
113 | return;\r | |
114 | }\r | |
3402aac7 | 115 | \r |
2ef2b01e A |
116 | \r |
117 | \r | |
118 | \r | |
119 | /**\r | |
3402aac7 | 120 | Embedded Boot Loader (EBL) - A simple EFI command line application for embedded\r |
7ca9e5a4 | 121 | devices. PcdEmbeddedAutomaticBootCommand is a complied in command line that\r |
122 | gets executed automatically. The ; separator allows multiple commands\r | |
2ef2b01e A |
123 | for each command line.\r |
124 | \r | |
125 | @param ImageHandle EFI ImageHandle for this application.\r | |
126 | @param SystemTable EFI system table\r | |
127 | \r | |
7ca9e5a4 | 128 | @return EFI status of the application\r |
2ef2b01e A |
129 | \r |
130 | **/\r | |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | EdkExternCmdEntry (\r | |
134 | IN EFI_HANDLE ImageHandle,\r | |
135 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
3402aac7 | 136 | )\r |
2ef2b01e A |
137 | {\r |
138 | EFI_STATUS Status;\r | |
139 | EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r | |
140 | UINTN Argc;\r | |
141 | CHAR8 *Argv[MAX_ARGS];\r | |
142 | \r | |
143 | Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r | |
144 | if (EFI_ERROR (Status)) {\r | |
145 | Argc = 0;\r | |
146 | } else {\r | |
3402aac7 | 147 | // Looks like valid commands were passed in.\r |
2ef2b01e A |
148 | ParseArguments (ImageInfo->LoadOptions, ImageInfo->LoadOptionsSize, &Argc, Argv);\r |
149 | }\r | |
3402aac7 | 150 | \r |
2ef2b01e A |
151 | return EblMain (Argc, Argv);\r |
152 | }\r | |
153 | \r | |
154 | \r |