4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/bootconf.h>
28 #include <sys/reboot.h>
29 #include <sys/param.h>
30 #include <sys/salib.h>
31 #include <sys/debug.h>
32 #include <sys/promif.h>
34 #include <sys/sysmacros.h>
35 #include <util/getoptstr.h>
36 #include "boot_plat.h"
38 static char default_path_buf
[MAXPATHLEN
];
40 char cmd_line_boot_archive
[MAXPATHLEN
];
45 * Parse the boot arguments, adding the options found to the existing boothowto
46 * value (if any) or other state. Then rewrite the buffer with arguments for
49 * NOTE: boothowto may already have bits set when this function is called
52 bootflags(char *args
, size_t argsz
)
54 static char newargs
[OBP_MAXPATHLEN
];
55 struct gos_params params
;
60 char *cmd_line_default_path
;
62 cmd_line_default_path
= NULL
;
64 params
.gos_opts
= "HXF:VnI:D:advhko:";
65 params
.gos_strp
= args
;
66 getoptstr_init(¶ms
);
67 while ((c
= getoptstr(¶ms
)) != -1) {
79 if (params
.gos_optarglen
>=
80 sizeof (cmd_line_boot_archive
)) {
81 printf("boot: -F argument too long. "
85 (void) strncpy(cmd_line_boot_archive
,
86 params
.gos_optargp
, params
.gos_optarglen
);
87 cmd_line_boot_archive
[params
.gos_optarglen
] = '\0';
98 printf("Warning: boot will not enable cache\n");
102 if (params
.gos_optarglen
>= sizeof (default_path_buf
)) {
103 printf("boot: -D argument too long. "
107 (void) strncpy(default_path_buf
, params
.gos_optargp
,
108 params
.gos_optarglen
);
109 default_path_buf
[params
.gos_optarglen
] = '\0';
110 cmd_line_default_path
= default_path_buf
;
114 boothowto
|= RB_ASKNAME
;
118 boothowto
|= RB_DEBUGENTER
;
121 boothowto
|= RB_VERBOSE
;
124 boothowto
|= RB_HALT
;
127 /* Consumed by the kernel */
129 boothowto
|= RB_KMDB
;
133 * Unrecognized flags: stop.
137 * Error. Either an unrecognized option, or an option
138 * without an argument. Check for the latter.
140 switch (params
.gos_last_opt
) {
144 printf("boot: -%c flag missing required "
145 "argument. Ignoring.\n",
146 params
.gos_last_opt
);
149 /* Unrecognized option. Stop. */
155 printf("boot: Ignoring unimplemented option -%c.\n", c
);
161 * Construct the arguments for the standalone.
168 * We need a dash if we encountered an unrecognized option or if we
169 * need to pass flags on.
171 if (c
== '?' || (boothowto
&
172 /* These flags are to be passed to the standalone. */
173 (RB_ASKNAME
| RB_DEBUGENTER
| RB_VERBOSE
| RB_HALT
| RB_KMDB
))) {
177 * boot(1M) says to pass these on.
179 if (boothowto
& RB_ASKNAME
)
183 * boot isn't documented as consuming these flags, so pass
186 if (boothowto
& RB_DEBUGENTER
)
188 if (boothowto
& RB_KMDB
)
190 if (boothowto
& RB_VERBOSE
)
192 if (boothowto
& RB_HALT
)
196 * If we didn't encounter an unrecognized flag and there's
197 * more to copy, add a space to separate these flags.
198 * (Otherwise, unrecognized flags can be appended since we
199 * started this word with a dash.)
201 if (c
== -1 && params
.gos_strp
[0] != '\0')
205 npres
= sizeof (newargs
) - (size_t)(np
- newargs
);
209 * Unrecognized flag: Copy gos_errp to end of line or a "--"
212 cp
= params
.gos_errp
;
213 while (*cp
&& npres
> 0) {
214 if (cp
[0] == '-' && cp
[1] == '-' &&
215 (cp
[2] == '\0' || ISSPACE(cp
[2]))) {
223 /* Copy until the next word. */
224 while (*cp
&& !ISSPACE(*cp
))
229 sz
= MIN(npres
, (size_t)(cp
- sp
));
236 cp
= params
.gos_strp
;
239 while (npres
> 0 && (*np
++ = *cp
++) != '\0')
242 newargs
[sizeof (newargs
) - 1] = '\0';
243 (void) strlcpy(args
, newargs
, argsz
);
246 * If a default filename was specified in the args, set it.
248 if (cmd_line_default_path
)
249 set_default_filename(cmd_line_default_path
);
252 * See if user wants to examine things