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 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/reboot.h>
29 #include <sys/cmn_err.h>
30 #include <sys/bootconf.h>
31 #include <sys/promif.h>
32 #include <sys/obpdefs.h>
33 #include <sys/sunddi.h>
34 #include <sys/systm.h>
36 #include <sys/kobj_impl.h>
37 #include <util/getoptstr.h>
39 char *kobj_kmdb_argv
[11]; /* 10 arguments and trailing NULL */
42 * Parse the boot line to determine boot flags.
45 bootflags(struct bootops
*ops
)
47 struct gos_params params
;
48 uchar_t num_O_opt
= 0;
51 char scratch
[BOOTARGS_MAX
];
53 if (BOP_GETPROP(ops
, "bootargs", kern_bootargs
) == -1) {
54 boothowto
|= RB_ASKNAME
;
58 (void) BOP_GETPROP(ops
, "boot-file", kern_bootfile
);
64 * Sparc only, _OBP isn't defined on x86 any more.
67 /* if user booted kadb or kmdb, load kmdb */
68 if (cp
[0] == 'k' && (cp
[1] == 'a' || cp
[1] == 'm') &&
69 cp
[2] == 'd' && cp
[3] == 'b' &&
70 (cp
[4] == ' ' || cp
[4] == ' ' || cp
[4] == 0))
72 SKIP_WORD(cp
); /* Skip the kernel's filename. */
78 /* skip bootblk args */
79 params
.gos_opts
= "abcdDf:F:gGHhi:km:o:O:rsvVwxZ:";
81 params
.gos_opts
= "abcdgGhi:km:O:rsvwx";
84 getoptstr_init(¶ms
);
85 while ((c
= getoptstr(¶ms
)) != -1) {
89 boothowto
|= RB_ASKNAME
;
92 boothowto
|= RB_NOBOOTRC
;
95 boothowto
|= RB_CONFIG
;
98 boothowto
|= RB_DEBUGENTER
;
105 (void) prom_setprop(prom_optionsnode(), "diag-level",
106 (char *)params
.gos_optargp
,
107 params
.gos_optarglen
+ 1);
111 boothowto
|= RB_FORTHDEBUG
;
114 boothowto
|= RB_FORTHDEBUGDBP
;
117 boothowto
|= RB_HALT
;
124 if (params
.gos_optarglen
+ 1 > sizeof (initname
)) {
125 _kobj_printf(ops
, "krtld: initname too long. "
128 (void) strncpy(initname
, params
.gos_optargp
,
129 params
.gos_optarglen
);
130 initname
[params
.gos_optarglen
] = '\0';
134 boothowto
|= RB_KMDB
;
137 if (strlen(initargs
) + 3 + params
.gos_optarglen
+ 1 >
140 "unix: init options too long. "
144 /* gos_optargp is not null terminated */
145 (void) strncpy(scratch
, params
.gos_optargp
,
146 params
.gos_optarglen
);
147 scratch
[params
.gos_optarglen
] = '\0';
148 (void) strlcat(initargs
, "-m ", sizeof (initargs
));
149 (void) strlcat(initargs
, scratch
,
151 (void) strlcat(initargs
, " ", sizeof (initargs
));
154 /* Ignore legacy wanboot argument meant for standalone */
159 char **str
= &kobj_kmdb_argv
[num_O_opt
];
161 if (++num_O_opt
> (sizeof (kobj_kmdb_argv
) /
162 sizeof (char *)) - 1) {
163 _kobj_printf(ops
, "krtld: too many kmdb "
164 "options - ignoring option #%d.\n",
169 *str
= kobj_alloc(params
.gos_optarglen
+ 1, KM_TMP
);
170 (void) strncpy(*str
, params
.gos_optargp
,
171 params
.gos_optarglen
);
172 (*str
)[params
.gos_optarglen
] = '\0';
176 if (strlen(initargs
) + 3 + 1 > sizeof (initargs
)) {
177 _kobj_printf(ops
, "unix: init options too "
178 "long. Ignoring -r.\n");
181 boothowto
|= RB_RECONFIG
;
182 (void) strlcat(initargs
, "-r ", sizeof (initargs
));
185 if (strlen(initargs
) + 3 + 1 > sizeof (initargs
)) {
186 _kobj_printf(ops
, "unix: init options too "
187 "long. Ignoring -s.\n");
190 boothowto
|= RB_SINGLE
;
191 (void) strlcat(initargs
, "-s ", sizeof (initargs
));
194 if (strlen(initargs
) + 3 + 1 > sizeof (initargs
)) {
195 _kobj_printf(ops
, "unix: init options too "
196 "long. Ignoring -v.\n");
199 boothowto
|= RB_VERBOSE
;
200 (void) strlcat(initargs
, "-v ", sizeof (initargs
));
209 boothowto
|= RB_WRITABLE
;
212 switch (params
.gos_last_opt
) {
214 _kobj_printf(ops
, "krtld: Required argument "
215 "for -i flag missing. Ignoring.\n");
218 _kobj_printf(ops
, "krtld: Ignoring invalid "
219 "kernel option -%c.\n",
220 params
.gos_last_opt
);
224 _kobj_printf(ops
, "krtld: Ignoring unimplemented "
229 if ((boothowto
& (RB_DEBUGENTER
| RB_KMDB
)) == RB_DEBUGENTER
) {
230 _kobj_printf(ops
, "krtld: -d is not valid without -k.\n");
231 boothowto
&= ~RB_DEBUGENTER
;
234 if (*params
.gos_strp
) {
235 /* Unused arguments. */
236 if (params
.gos_strp
[0] == '-' && ISSPACE(params
.gos_strp
[1])) {
238 /* Lousy install arguments. Silently ignore. */
240 _kobj_printf(ops
, "krtld: Unused kernel arguments: "
241 "`%s'.\n", params
.gos_strp
);