wok-current view linld/stuff/src/LINLD.CPP @ rev 21628
linld: more ram for zImage (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon May 27 23:23:13 2019 +0200 (2019-05-27) |
parents | 66530154b12f |
children | 93f070d4d2d7 |
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=rw root=/dev/null 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,"image=") != -1) {
93 s+=6;
94 set_kernel_name:
95 kernel_name=s;
96 }
97 else if(strhead(s,"initrd=") != -1) {
98 initrd_name=s+7;
99 }
100 else if(strhead(s,"vga=") != -1) {
101 *(u16*)&vid_mode = (u16)strtol(s+7); // support normal, extended & ask
102 }
103 else switch (*(u16 *)s|0x2002) {
104 case 0x662F: // -F /f
105 skip_alloc++;
106 goto next;
107 case 0x622F: // -B /b
108 argv++;
109 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
110 goto next;
111 default:
112 if(strhead(s,"cl=") != -1) {
113 cmdline=s+=3;
114 if (*s == '@') {
115 static struct image_himem image;
116 char c;
118 s++;
119 image.errmsg = "Error in cl=@file";
120 open_image(s, &image);
121 s+=read(image.fd, (void *)cmdline=s=
122 (char *)malloc_or_die(image.size), image.size);
123 // Strip any trailing cr/lf
124 c='\0';
125 do {
126 // Replace all other cr/lfs with spaces
127 s--;
128 if(*s>=' ') c=' ';
129 else *s = c;
130 } while (s>cmdline);
131 puts("Kernel command line:");
132 puts(cmdline);
133 }
134 }
135 else if(strhead(s,"root=") != -1) {
136 *(u16*)&root_dev = (u16)strtol(s+5);
137 goto addincmdline;
138 }
139 else if(strhead(s,"mem=") != -1) {
140 ((u16 *)&topmem)[1] = (u16)(strtol(s+4)>>16);
141 goto addincmdline;
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 }