File: /usr/src/linux/arch/mips64/arc/cmdline.c

1     /*
2      * This file is subject to the terms and conditions of the GNU General Public
3      * License.  See the file "COPYING" in the main directory of this archive
4      * for more details.
5      *
6      * cmdline.c: Kernel command line creation using ARCS argc/argv.
7      *
8      * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
9      */
10     #include <linux/init.h>
11     #include <linux/kernel.h>
12     #include <linux/string.h>
13     
14     #include <asm/sgialib.h>
15     #include <asm/bootinfo.h>
16     
17     /* #define DEBUG_CMDLINE */
18     
19     char arcs_cmdline[CL_SIZE];
20     
21     char * __init prom_getcmdline(void)
22     {
23     	return &(arcs_cmdline[0]);
24     }
25     
26     static char *ignored[] = {
27     	"ConsoleIn=",
28     	"ConsoleOut=",
29     	"SystemPartition=",
30     	"OSLoader=",
31     	"OSLoadPartition=",
32     	"OSLoadFilename=",
33     	"OSLoadOptions="
34     };
35     #define NENTS(foo) ((sizeof((foo)) / (sizeof((foo[0])))))
36     
37     static char *used_arc[][2] = {
38     	{ "OSLoadPartition=", "root=" },
39     	{ "OSLoadOptions=", "" }
40     };
41     
42     static char * __init move_firmware_args(char* cp)
43     {
44     	char *s;
45     	int actr, i;
46     
47     	actr = 1; /* Always ignore argv[0] */
48     
49     	while (actr < prom_argc) {
50     		for(i = 0; i < NENTS(used_arc); i++) {
51     			int len = strlen(used_arc[i][0]);
52     
53     			if (!strncmp(prom_argv(actr), used_arc[i][0], len)) {
54     			/* Ok, we want it. First append the replacement... */
55     				strcat(cp, used_arc[i][1]);
56     				cp += strlen(used_arc[i][1]);
57     				/* ... and now the argument */
58     				s = strstr(prom_argv(actr), "=");
59     				if (s) {
60     					s++;
61     					strcpy(cp, s);
62     					cp += strlen(s);
63     				}
64     				*cp++ = ' ';
65     				break;
66     			}
67     		}
68     		actr++;
69     	}
70     
71     	return cp;
72     }
73     
74     
75     void __init prom_init_cmdline(void)
76     {
77     	char *cp;
78     	int actr, i;
79     
80     	actr = 1; /* Always ignore argv[0] */
81     
82     	cp = &(arcs_cmdline[0]);
83     	/* 
84     	 * Move ARC variables to the beginning to make sure they can be
85     	 * overridden by later arguments.
86     	 */
87     	cp = move_firmware_args(cp);
88     
89     	while (actr < prom_argc) {
90     		for (i = 0; i < NENTS(ignored); i++) {
91     			int len = strlen(ignored[i]);
92     
93     			if (!strncmp(prom_argv(actr), ignored[i], len))
94     				goto pic_cont;
95     		}
96     		/* Ok, we want it. */
97     		strcpy(cp, prom_argv(actr));
98     		cp += strlen(prom_argv(actr));
99     		*cp++ = ' ';
100     
101     	pic_cont:
102     		actr++;
103     	}
104     	if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
105     		--cp;
106     	*cp = '\0';
107     
108     #ifdef DEBUG_CMDLINE
109     	prom_printf("prom_init_cmdline: %s\n", &(arcs_cmdline[0]));
110     #endif
111     }
112