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 (davem@davemloft.net)
9 */
10 #include <linux/bug.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/string.h>
14
15 #include <asm/sgialib.h>
16 #include <asm/bootinfo.h>
17
18 #undef DEBUG_CMDLINE
19
20 /*
21 * A 32-bit ARC PROM pass arguments and environment as 32-bit pointer.
22 * These macro take care of sign extension.
23 */
24 #define prom_argv(index) ((char *) (long)argv[(index)])
25
26 static char *ignored[] = {
27 "ConsoleIn=",
28 "ConsoleOut=",
29 "SystemPartition=",
30 "OSLoader=",
31 "OSLoadPartition=",
32 "OSLoadFilename=",
33 "OSLoadOptions="
34 };
35
36 static char *used_arc[][2] = {
37 { "OSLoadPartition=", "root=" },
38 { "OSLoadOptions=", "" }
39 };
40
move_firmware_args(int argc,LONG * argv,char * cp)41 static char __init *move_firmware_args(int argc, LONG *argv, char *cp)
42 {
43 char *s;
44 int actr, i;
45 size_t len;
46
47 actr = 1; /* Always ignore argv[0] */
48
49 while (actr < argc) {
50 for (i = 0; i < ARRAY_SIZE(used_arc); i++) {
51 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 = strchr(prom_argv(actr), '=');
59 if (s) {
60 s++;
61 len = strlen(s);
62 memcpy(cp, s, len + 1);
63 cp += len;
64 }
65 *cp++ = ' ';
66 break;
67 }
68 }
69 actr++;
70 }
71
72 return cp;
73 }
74
prom_init_cmdline(int argc,LONG * argv)75 void __init prom_init_cmdline(int argc, LONG *argv)
76 {
77 char *cp;
78 int actr, i;
79 size_t len;
80
81 actr = 1; /* Always ignore argv[0] */
82
83 cp = arcs_cmdline;
84 /*
85 * Move ARC variables to the beginning to make sure they can be
86 * overridden by later arguments.
87 */
88 cp = move_firmware_args(argc, argv, cp);
89
90 while (actr < argc) {
91 for (i = 0; i < ARRAY_SIZE(ignored); i++) {
92 len = strlen(ignored[i]);
93 if (!strncmp(prom_argv(actr), ignored[i], len))
94 goto pic_cont;
95 }
96
97 /* Ok, we want it. */
98 len = strlen(prom_argv(actr));
99 memcpy(cp, prom_argv(actr), len + 1);
100 cp += len;
101 *cp++ = ' ';
102
103 pic_cont:
104 actr++;
105 }
106
107 if (cp != arcs_cmdline) /* get rid of trailing space */
108 --cp;
109 *cp = '\0';
110
111 #ifdef DEBUG_CMDLINE
112 pr_debug("prom cmdline: %s\n", arcs_cmdline);
113 #endif
114 }
115