wok view linld/stuff/src/LINLD.CPP @ rev 21822

Remove unused kernel cmdline args root=/dev/null
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 25 18:00:45 2019 +0200 (8 weeks ago)
parents 04ffefac5707
children 6e3d30b3031f
line source
1 // This file is distributed under GPL
2 //
3 // LINLD main() lives here
5 #include "crtl.h"
6 #include "common.h"
8 const char* kernel_name = "bzImage";
9 const char* initrd_name;
10 const char* cmdline = "auto";
11 u32 root_dev;
12 u32 vid_mode; // -3 = ask
13 // -2 = Extended VGA
14 // -1 = Normal VGA
15 // n = as "n" was pressed
16 u32 topmem;
17 u32 base_himem;
19 inline void syntax() {
20 die("Syntax:" NL
21 "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL
22 "vga mode: ask,extended,normal or dec/oct/hex number" NL
23 "-f force" NL
24 "Defaults:" NL
25 "\timage=bzImage" NL
26 "\tinitrd,vga,root=(void)" NL
27 "\tmem=256m" NL
28 "\tcl=auto" NL
29 "\t-b 1088k" NL
30 "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
31 "Use cl=@filename to get it from a file"
32 #if 1
33 NL NL "Examples:" NL
34 "\tLINLD -f -b 64m "
35 "initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz "
36 "\"cl=video=-32\""
37 NL NL "\tLINLD image=memtest"
38 #endif
39 );
40 }
42 static char buf_cmdline[128];
43 int main(int argc, char *argv[]) {
45 (void) argc;
47 ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k
48 puts("LINLD v" VERSION_STR "+");
50 // Parse command line
51 #ifdef USE_ARGSTR
52 if (!argv[1]) syntax();
53 {for (;;) {
54 const char **clp = &cmdline;
55 next:
56 argv++;
57 if (!*argv) {
58 puts(*clp);
59 set_cmdline(*clp);
60 puts(load_kernel());
61 load_initrd();
62 boot_kernel();
63 }
64 if ((*(u16 *)*argv|0x2002) == 0x662F) { // -F /f
65 skip_alloc++;
66 goto next;
67 }
68 if (argstr(*argv,"cl|image|initrd",clp) != -1);
69 else if (fileexist(*argv) != -1)
70 kernel_name=*argv;
71 else if (*argv) {
72 argnum(*argv,"root|vga|mem|-b",&root_dev);
73 *clp = (const char *) buf_cmdline + 1;
74 strcatb((const char *) buf_cmdline,*argv);
75 }
76 else
77 break;
78 }
79 }
80 #else
81 if (!argv[1]) syntax();
82 while (1) {
83 char *s;
84 next:
85 argv++;
86 s=*argv;
87 if (!s) {
88 puts(load_kernel());
89 load_initrd();
90 boot_kernel();
91 }
92 if(strhead(s,"initrd=") != -1) {
93 initrd_name=s+7;
94 }
95 else if(strhead(s,"vga=") != -1) {
96 *(u16*)&vid_mode = (u16)strtol(s+7); // support normal, extended & ask
97 }
98 else switch (*(u16 *)s|0x2002) {
99 case 0x662F: // -F /f
100 skip_alloc++;
101 goto next;
102 case 0x622F: // -B /b
103 argv++;
104 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
105 goto next;
106 default:
107 if(strhead(s,"cl=") != -1) {
108 cmdline=s+=3;
109 if (*s == '@') {
110 static struct image_himem image;
111 char c;
113 s++;
114 image.errmsg = "Error in cl=@file";
115 open_image(&image, s);
116 s+=read(image.fd, (void *)cmdline=s=
117 (char *)malloc_or_die(image.size), image.size);
118 // Strip any trailing cr/lf
119 c='\0';
120 do {
121 // Replace all other cr/lfs with spaces
122 s--;
123 if(*s>=' ') c=' ';
124 else *s = c;
125 } while (s>cmdline);
126 puts("Kernel command line:");
127 puts(cmdline);
128 }
129 }
130 else if(strhead(s,"root=") != -1) {
131 *(u16*)&root_dev = (u16)strtol(s+5);
132 goto addincmdline;
133 }
134 else if(strhead(s,"mem=") != -1) {
135 ((u16 *)&topmem)[1] = (u16)(strtol(s+4)>>16);
136 goto addincmdline;
137 }
138 else if(strhead(s,"image=") != -1) {
139 s+=6;
140 set_kernel_name:
141 kernel_name=s;
142 }
143 else {
144 addincmdline:
145 if(cmdline == (const char *) buf_cmdline + 1) {
146 strcatb(buf_cmdline,*argv);
147 }
148 else {
149 if(fileexist(s) != -1) goto set_kernel_name;
150 cmdline = (const char *) buf_cmdline + 1;
151 goto addincmdline;
152 }
153 }
154 }
155 }
156 #endif
158 // Let compiler be happy
159 return _AX;
160 }