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

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