wok-current view linld/stuff/src/TAZBOOT.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 | c19368210c2b |
line source
1 // This file is distributed under GPL
2 //
3 // TAZBOOT main() lives here
5 #include "crtl.h"
6 #include "crtlx.h"
7 #include "common.h"
8 #include "iso9660.h"
10 struct initrd_info {
11 u32 ofs;
12 u32 size;
13 };
14 #define MAXINITRD 10
15 static struct initrd_state {
16 struct initrd_info info[MAXINITRD];
17 u16 cnt;
18 } initrd_state;
20 static void next_chunk(struct image_himem *m)
21 {
22 struct initrd_info *i = &initrd_state.info[m->state];
23 m->chunk_size = 0;
24 if (m->state >= initrd_state.cnt) return;
25 lseekset2(m->fd,&i->ofs);
26 m->chunk_size = i->size;
27 m->state++;
28 }
30 static u32 isofilesize4round()
31 {
32 return (isofilesize+3)&-4;
33 }
35 static void addinitrd()
36 {
37 u16 *pcnt = &initrd_state.cnt;
38 struct initrd_info *i = &initrd_state.info[*pcnt];
39 if (*pcnt >= MAXINITRD) return;
40 ++*pcnt;
41 i->size = isofilesize;
42 i->ofs = isofileofs;
43 initrd.size += isofilesize4round();
44 }
46 static void load_initrds()
47 {
48 struct image_himem *m = &initrd;
49 if (!m->size) return;
50 m->next_chunk = next_chunk;
51 m->fd = isofd;
52 m->state = 0;
53 next_chunk(m);
54 load_initrd();
55 }
57 static char *isokernel()
58 {
59 struct image_himem *m = ±
60 m->chunk_size = m->size = isofilesize4round();
61 m->fd = isofd;
62 return load_kernel();
63 }
65 static char buf_cmdline[4096];
66 const char *cmdline = (const char *) buf_cmdline+1;
67 static void bootiso(char **iso)
68 {
69 const char *init = " rdinit=/init.exe", *mode="menu";
70 char c;
71 static char rootfs[16], fallback[16], isknoppix, noauto;
72 unsigned long magic;
73 struct isostate *x=&isostate;
75 if (isoreset(*iso) == -1) return;
76 skip_alloc++;
77 base_himem = memtop() /2;
78 //if (base_himem >= _64m) base_himem = _64m;
79 if (* ((char *) &base_himem +3) >= 4) base_himem = _64m;
80 isoopen("boot") != -1 ||
81 isoopen("live") != -1 || // debian
82 isoopen("casper") != -1; // ubuntu
83 if (iso[1] && !strcmp(mode = iso[1], "text"))
84 init = "";
85 do {
86 if ((isoopen(mode) != -1 && ++noauto != 0) || // custom
87 isoopen("bzImage") != -1 || // SliTaz
88 isoopen("vmlinuz") != -1 || // misc
89 (isoopen("linux") != -1 && ++isknoppix != 0)) {
90 magic = kver2ul(isokernel());
91 break;
92 }
93 } while (isoopen("isolinux") != -1); // Knoppix
94 for (c = 0, x->curdirsize = 0xFFFF; isoreaddir() != -1;) {
95 if (strstr(x->filename, ".gz"))
96 strcpy(fallback, x->filename);
97 if (strhead(x->filename, "rootfs") == -1
98 || c > x->filename[6]) continue;
99 strcpy(rootfs, x->filename);
100 c = x->filename[6];
101 }
103 strcatb(buf_cmdline,"rw root=/dev/null autologin bootfrom=");
104 strcat(buf_cmdline,*iso);
105 if (magic < 0x20630)
106 init = ""; // Does not support multiple initramfs
108 if (noauto) {
109 char *s;
110 * (int *) buf_cmdline = 0;
111 iso++;
112 while ((s = *++iso) != NULL) {
113 if (strhead(s,"initrd=") == -1)
114 strcatb(buf_cmdline,s);
115 else if (isoopen(s+7) != -1)
116 addinitrd();
117 }
118 }
119 else if (magic > 0) {
120 char *initrdfilename = fallback;
121 static const unsigned long initrddesc = 18L;
123 if (rootfs[0]) {
124 initrdfilename = rootfs;
125 if (rootfs[6] != '.' && isoopen("rootfs.gz") != -1)
126 addinitrd(); // for loram
127 }
128 if (isoopen(initrdfilename) != -1) {
129 addinitrd();
130 }
131 if (*init && isolseek(&initrddesc) != 0) {
132 read(x->fd, &x->filemod, 10); // + x->fileofs & x->filesize
133 magic = x->filemod;
134 x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
135 if (((short *) &x->fileofs)[1] == 0) addinitrd();
136 else init="";
137 }
138 strcat(buf_cmdline,init);
139 strcatb(buf_cmdline,"mode=");
140 strcat(buf_cmdline,mode);
141 strcatb(buf_cmdline,"magic=");
142 strcat(buf_cmdline,(char *)ultoa(magic));
143 }
144 load_initrds();
145 if (isknoppix) {
146 char *s = *iso;
147 if (s[1] == ':')
148 s += 2;
149 for (; *s; s++)
150 if (*s == '\\') *s = '/';
151 }
152 close(x->fd);
153 boot_kernel();
154 }
156 u32 root_dev;
157 u32 vid_mode;
158 u32 topmem;
159 u32 base_himem;
160 const char* kernel_name = "bzImage";
161 const char* initrd_name;
162 char* iso;
164 int main(int argc, char *argv[])
165 {
166 ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k
167 argv[0] = progname();
168 bootiso(argv); // iso ? parsing is /init.exe stuff !
170 if (argc < 2) {
171 try_default_args();
172 dousage:
173 die("Usage: tazboot [[@commands]|[-f][-b base_himem][kernel=<bzImage>] \
174 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] ...]\r\n\n\
175 Defaults: tazboot kernel=bzImage auto\r\n\n\
176 Examples for tazboot.cmd:\r\n\n\
177 bootfrom=\\isos\\slitaz-4.0.iso\r\n\
178 kernel=boot/bzImage\r\n\
179 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz,\\slitaz\\extrafs.gz\r\n\
180 rw root=/dev/null vga=normal autologin\r\n\n\
181 kernel=\\slitaz\\elks\r\n\
182 root=/dev/bda1 ro\r\n");
183 }
184 bootiso(argv + 1);
185 chdirname(*argv);
186 for (int i=0;;) {
187 char *s;
188 next: argv++;
189 s=*argv;
190 i++;
191 if (!s) break;
192 #ifdef USE_ARGSTR
193 if ((*(u16 *)s|0x2002) == 0x662F) { // -F /f
194 skip_alloc++;
195 goto next;
196 }
197 if (argstr(s,"kernel/image|initrd|bootfrom/iso",&kernel_name) != -1);
198 else if (argnum(s,"root|vga|mem/-e|-b",&root_dev) != -1);
199 else if(i == 1 && fileexist(s) != -1) {
200 kernel_name = s;
201 }
202 else strcatb(buf_cmdline,*argv); // FIXME mem ?
203 }
204 #else
205 if (strhead(s,"kernel=") != -1) {
206 s++;
207 set_kernel:
208 s += 6;
209 set_kernelz:
210 kernel_name = s;
211 }
212 else if (strhead(s,"image=") != -1) {
213 goto set_kernel;
214 }
215 else if (strhead(s,"initrd=") != -1) {
216 s += 7;
217 initrd_name = s;
218 }
219 else if (strhead(s,"bootfrom=") != -1) {
220 s += 9;
221 set_iso:
222 iso = s;
223 }
224 else if (strhead(s,"iso=") != -1) {
225 s += 4;
226 goto set_iso;
227 }
228 else if(strhead(s,"vga=") != -1) {
229 *(u16*)&vid_mode = (u16)strtol(s+4); // support normal, extended & ask
230 }
231 else switch (*(u16 *)s|0x2002) {
232 case 0x662F: // -F /f
233 skip_alloc++;
234 goto next;
235 case 0x652F: // -E /e
236 s=*++argv;
237 goto set_topmem;
238 case 0x622F: // -B /b
239 argv++;
240 ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16);
241 goto next;
242 default:
243 if(i == 1 && fileexist(s) != -1) {
244 goto set_kernelz;
245 }
246 else {
247 strcatb(buf_cmdline,*argv);
248 if(strhead(s,"root=") != -1) {
249 *(u16*)&root_dev = (u16)strtol(s+5);
250 }
251 if(strhead(s,"mem=") != -1) {
252 s += 4;
253 set_topmem:
254 ((u16 *)&topmem)[1] = (u16)(strtol(s)>>16);
255 }
256 }}
257 }
258 #endif
259 if (isoreset(iso) != -1) {
260 char *s = (char *) initrd_name;
261 if (isoopen((char *) kernel_name) != -1) {
262 isokernel();
263 }
264 if (s) {
265 while (*s) {
266 char *p, c;
267 for (p = s; *s && *s != ','; s++);
268 c = *s; *s = 0;
269 if (isoopen(p) != -1) {
270 addinitrd();
271 }
272 *s = c;
273 if (c) s++;
274 }
275 load_initrds();
276 }
277 }
278 else {
279 load_kernel();
280 load_initrd();
281 }
282 boot_kernel();
283 return _AX;
284 }