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